Upload Help

SpaceshipSpaceship
Watch

snike

Established Member
Impact
3
OK I have this:
PHP:
//MOVE BUTTON TO FOLDER
if(move_uploaded_file ($_FILES['upload']['tmp_name'],"buttons/{$_FILES['upload']['name']}")) {
print "";
} else {
print "There was a problem uploading your file.";
exit;
}
I want it so that the file they are uploading already exists it changes to another name.

For example. A person uploads the file button.jpg. that file is uploaded. Now antoher person also uploads button.jpg but the name is changed to button4824,jpg or something like that.

also how can i make it so that they can only upload .jpg .gif and .png?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
Is this an image host?

Instead of allowing an original name, the best way to avoid this is to save each image with a new name, usually a random name.
So say someone uploaded button.jpg, you could make it sdfg23sfd234gsdgdg_button.jpg
If another peson uploaded something called button.jpg, the random jibberish at the end would be different, thus avoiding overwriting files.
PHP:
//Create unique jibberish
$unique = substr(md5(uniqid(rand())),0,10);
//MOVE BUTTON TO FOLDER
if(move_uploaded_file ($_FILES['upload']['tmp_name'],"buttons/".$unique."_".$_FILES['upload']['name'])) {
print "";
} else {
print "There was a problem uploading your file.";
exit;
}

That oughta do it for you if you'd like that kind of system.

Hope it helps,
Rhett.
 
0
•••
PHP:
if (isset($_FILES["upload"]["name"]));
{
if (($_FILES["upload"]["type"] == "image/png")
{
$unique = substr(md5(uniqid(rand())),0,10);
//MOVE BUTTON TO FOLDER
if(move_uploaded_file ($_FILES['upload']['tmp_name'],"buttons/".$unique."_".$_FILES['upload']['name'])) 
{
print "";
}
else
{
echo "There was a problem uploading your file.";
exit;
}  
}


if (($_FILES["upload"]["type"] == "image/gif")
{
$unique = substr(md5(uniqid(rand())),0,10);
//MOVE BUTTON TO FOLDER
if(move_uploaded_file ($_FILES['upload']['tmp_name'],"buttons/".$unique."_".$_FILES['upload']['name']))
{
print "";
}
else
{
echo "There was a problem uploading your file.";
exit;
}  
}


if (($_FILES["upload"]["type"] == "image/jpg")
{
$unique = substr(md5(uniqid(rand())),0,10);
//MOVE BUTTON TO FOLDER
if(move_uploaded_file ($_FILES['upload']['tmp_name'],"buttons/".$unique."_".$_FILES['upload']['name'])) 
{
print "";
}
else
{
echo "There was a problem uploading your file.";
exit;
}  
}
}
else
{
echo "There was a problem uploading your file."


Maybe, the code is very scrappy cuz im tired, if it doesnt work, PM or wait till someone else posts :)

Also i included billy connites code for the random string, so yeah, give him credit.
 
Last edited:
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back