Page 1 of 1

file upload

Posted: Tue Jun 02, 2009 5:41 pm
by lammspillning
I have this code to take care of my files I upload on my server. But sometimes files get skipped and won't upload. How can I in that case retry the script to give the file a new shot?

Code: Select all

move_uploaded_file($_FILES['Filedata']['tmp_name'], "../media/uploads/". $myVariable. ".jpg");

Re: file upload

Posted: Tue Jun 02, 2009 6:35 pm
by mikemike

Code: Select all

if(move_uploaded_file($_FILES['Filedata']['tmp_name'], "../media/uploads/". $myVariable. ".jpg")){
  // do somethine
} else {
  move_uploaded_file($_FILES['Filedata']['tmp_name'], "../media/uploads/". $myVariable. ".jpg"); // Second attempt
}
Obviously you could put this into a loop but then you'd need to ensure you don't get stuck in an infinite loop when something goes wrong (like when the users file is too large)