Hi, I have a image upload thing on my website and I was wondering how do I make it so that if the image name that is being uploaded already exists for it to automatically rename the photo to something else. Here is the code:
<?
// postPic.php:
// ------------
//checks if the input is filled. could use $photo != "none".
if($photo_size){
//Checks for file type:
$ext=substr($photo_name,-4);
//strcasecmp used for .jpg <> .JPG
if (strcasecmp($ext,".jpg") or strcasecmp($ext,".gif") or strcasecmp($ext,".bmp") or strcasecmp($ext,".png")){
if($ext != ".jpg" && $ext != ".gif" && $ext != ".bmp" && $ext != ".jpeg")
die("File type non valid, use .jpeg, .jpg, .gif or .bmp");
}
//Saving the photo:
if(is_uploaded_file($photo)){
$photoFile = "../image_upload/$photo_name";
move_uploaded_file($photo, $photoFile);
//Add this lines to update your database:
//$query = "UPDATE $curDb SET photoFile='$photoFile'";
//mysql_query($query);
echo ("<font face='arial' size='2'>
<center>
<p><b><font size='5' face='Arial'>You Bastards Picture Upload</font></b></p>
<p><b><font size='4' color='#800080' face='Arial'>File Uploaded</font></b></p>
</center>
<p><center><img src=http://you-bastards.net/image_upload/$photoFile></center>
<p align='center'> </p>
<center>
<table>
<tr>
<td align='left'>
<font size='2'>
<strong>Name</strong>
</font>
</td>
<td>
<font size='2'>
$photo_name
</font>
</td>
</tr>
<tr>
<td align='left'>
<font size='2'>
<strong>Size</strong>
</font>
</td>
<td align='left'>
<font size='2'>
$photo_size
</font>
</td>
</tr>
<tr>
<td align='left'>
<font size='2'>
<strong>Extension</strong>
</font>
</td>
<td align='left'>
<font size='2'>
$ext
</font>
</td>
</tr>
<tr>
<td align='left'>
<font size='2'>
<strong>Image Address</strong>
</font>
</td>
<td align='left'>
<font size='2'>
http://you-bastards.net/image_upload/$photo_name
</font>
</td>
</tr>
</table>
");
}
}
//the HTML form <input type="hidden" name="MAX_FILE_SIZE" value="200000">
//sets $photo_size to 0 if the file > 200k
else if($photo_name != "" && $photo_size == "0")
die("File size must be smaller than 1200k");
else
echo "<font face='arial' size='2'>
<center>
<p><b><font size='5' face='Arial'>You Bastards Picture Upload</font></b></p>
<p><b><font size='4' color='#800080' face='Arial'>No $PageName File Uploaded</font></b></p>
</center>
<p align='center'> </p>
<center>
No file was selected";
?>