file upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lammspillning
Forum Newbie
Posts: 14
Joined: Fri Aug 17, 2007 10:50 am

file upload

Post 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");
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: file upload

Post 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)
Post Reply