Can someone please take a look at this and help me do one thing?
I am uploading images to a directory and updating the users record with the photo they upload. Problem is, I could have someone upload a photo with the same name as a photo that is already on the server. If this happens, then the photo for the exsisting profile will be over written.
I am trying to add the userid to the image name and the database record.
Here is my code:
<?php
if($_GET == 'upload')
{
//upload all the fields until done
For($i=0; $i <= $_i-1; $i++)
{
//create a random number
$_random = rand(1, 1000000);
//file with the upload folder
$target_path = $upload_dir . basename($_FILES);
$target_path = str_replace (" ", "", $target_path);
//actual file name with the random number
$_file_name = basename($_FILES);
$_file_name = str_replace (" ", "", $_file_name);
//do not upload the 'left blank' fields
if(basename($_FILES) != '')
{
if(move_uploaded_file($_FILES, $target_path))
{
//uploaded successfuly
$_uploaded=1;
}
else
{
//error uploading
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}
//file(s) did upload
if($_uploaded == '1')
{
$_uploaded=0;
echo "<div style=\"COLOR: #339900; font-size: 8pt; font-weight: bold; padding-top: 10px;\">The file have been uploaded.</div>";
mysql_query("update tbl_accounts set photo = '".$_file_name."' WHERE userID = '$passcode'");
}
//file uploaded?
if($_error == '1')
{
$_error=0;
echo "<div style=\"COLOR: #ff0000; font-size: 8pt; font-weight: bold; padding-top: 10px;\">There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}
//user selected a file?
if($_check == $_i)
{
$_check=0;
echo "<div style=\"COLOR: #ff0000; font-size: 8pt; font-weight: bold; padding-top: 10px;\">Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";
?>
</table>