Find jobs - Debt Consolidation - Debt Consolidation - Debt Consolidation - Herbal Supplements

PDA

View Full Version : file upload


lammspillning
Jun 2nd 2009, 3:43 pm
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?
move_uploaded_file($_FILES['Filedata']['tmp_name'], "../media/uploads/". $myVariable. ".jpg");

tguillea
Jun 3rd 2009, 2:13 am
Your best bet is to simply check if the file exists, and then redirect them back to the upload page if it failed.

this should do the trick

if (file_exists($_FILES['Filedata']['tmp_name'])){
move_uploaded_file($_FILES['Filedata']['tmp_name'], "../media/uploads/".$myVariable. ".jpg");
} else {
header('location: upload.php');
exit();
}