This is an avatar uploader i have.. Anyhow im having some problems with files already existing so i would need it to rename the uploaded files, something random maybe.. maybe someone could help me out?
thanks in advance
<?
session_start();//starts the session
if ($user['username']){ //If the user is logged in
print "<h3>Welcome to the avatar uploader</h3>";
print "<form method=\"post\" enctype=\"multipart/form-data\" name=\"form1\">";//Set the form and the type
print "Please select your .jpg avatar<br />";//Tell the user to select an image
print "<input type=\"file\" name=\"file\" /><br /><br />";//A file input box
print "<input type=\"submit\" name=\"fsubmit\" value=\"Upload\">";//Submit / upload button
print "</form>"; //End for
}
if ($_POST['fsubmit']){ //If the form has been submit
if ($_FILES['file']['size'] >= "500000"){ //If the file size is greater than 500000b
print "<br />Your file size must be less than <strong>50000kb</strong>!<br />"; //Error message
}
elseif ($_FILES['file']['size'] <= "500000"){ //If not and the file is less than 500000b
print "<strong>Upload Status</strong><br />"; //Show the upload status
if($_FILES) { //If the file exists
print "<strong>File exists</strong>"; //Tell the user
}
else //If not
{
print "<strong>File doesn't exist</strong>"; //Error message
}
$folder = "img/avatar";
move_uploaded_file($_FILES['file']['tmp_name'], "$folder/".$_FILES['file']['name'])or die ("<br />Could not copy"); //Move the file to the specified folder, or show an error message
$location= $_FILES['file']['name'];
$update = mysql_query("UPDATE users SET av = '$location' WHERE id = $users[id]")or die ("The avatar was not added to the specified user!");//Query the database
print "<br />"; //Line break
print "Name: ".$_FILES['file']['name']."<br />"; //Name of the file
print "URL: /$folder/".$_FILES['file']['name']."<br />"; //URL of the uploaded file
print "Size: ".$_FILES['file']['size']."<br />"; //Show the size of the file
print "Type: ".$_FILES['file']['type']."<br />"; //Show the file type
print "<br />"; //Line break
print "-------------------------"; //Lots of ----
print "<br />"; //Line break
print "<strong>Avatar Set!</strong>"; //Confirmation message
}
}
?>