File overwrite?
Posted: Sat Aug 27, 2011 1:19 pm
Morning fellow geeks of phpdn.
Quick question. I'm working on a file upload system and I've ran into the problem if a files exists on the server. I'm doing a check to see if it exists and if it dose then stops the upload (well move uploaded file in this case).
What I'm trying to figure out is there a way to over write it? I was curious if just doing something like moving it anyway after a prompt will overwrite it using "move_uploaded_file()"? Or was there something special I should do?
On a side note if anyone knows off hand, how long will a server by default keep the temp uploaded file before removing it if it was not renamed on the move?
Quick question. I'm working on a file upload system and I've ran into the problem if a files exists on the server. I'm doing a check to see if it exists and if it dose then stops the upload (well move uploaded file in this case).
Code: Select all
if ((($_FILES["file1"]["type"] == "image/gif") || ($_FILES["file1"]["type"] == "image/jpeg") ||($_FILES["file1"]["type"] == "image/pjpeg")) && ($_FILES["file1"]["size"] < 100000)){ //check to see if the file uploaded is allowed
if ($_FILES["file1"]["error"] > 0){
echo "<br />There was an error with the file upload: <br />";
echo "Return Code: " . $_FILES["file1"]["error"] . "<br />"; //print error
}else{
if(file_exists("upload/" . $_FILES["file1"]["name"])){ //check to see if the file name already exists in upload folder
echo $_FILES["file1"]["name"] . " already exists. ";
}else{
move_uploaded_file($_FILES["file1"]["tmp_name"],
"upload/" . $_FILES["file1"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file1"]["name"]; //move file to upload dir
}
}On a side note if anyone knows off hand, how long will a server by default keep the temp uploaded file before removing it if it was not renamed on the move?