oceans Posted August 8, 2007 Share Posted August 8, 2007 Dear Friends, I am using the following code to upload files (3 files at one go in a single page!) move_uploaded_file($_FILES["file".$i]["tmp_name"],"../../Photos/" .$_FILES["file".$i]["name"]); ["file".$i] indicates file "upload slots" on the page. I am concerned with ["tmp_name"], is this a string or an indicator to PHP file upload handler, I am worried what will happen if two concurrent user uploads files will the file get mixed up? If so I can try to device a way by replacing ["tmp_name"]. Can any one help, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/ Share on other sites More sharing options...
MadTechie Posted August 8, 2007 Share Posted August 8, 2007 Humm can you post the form please, as normally i would create an array ie <?php $base_path = "uploads/"; foreach($_FILES['MyFiles']['tmp_name'] as $FN => $File) { $target_path = $base_path . basename( $_FILES['MyFiles']['name'][$FN]); if(move_uploaded_file($_FILES['MyFiles']['tmp_name'][$FN], $target_path)) { echo "The file ". basename( $_FILES['MyFiles']['name'][$FN])." has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } ?> <form method="post" enctype="multipart/form-data"> <input name="MyFiles[]" type="file" /><br /> <input name="MyFiles[]" type="file" /><br /> <input name="MyFiles[]" type="file" /><br /> <input name="MyFiles[]" type="file" /><br /> <input name="MyFiles[]" type="file" /><br /> <input name="Done" type="submit" value="Upload" /> </form> **UNTESTED and can be improved but you get the idea Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318554 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 MadTechie, Thanks for your hand, my code does not use array (because I am not good at it) simple "for" loop. You are using what I an using if(move_uploaded_file($_FILES['MyFiles']['tmp_name'][$FN], $target_path)) what is ['tmp_name'] is it a PHP directive or a string value? I am worried if 2 "racing" pages comes in and one ['tmp_name'] is created and the second overwrites this before this got transfered for the first, do you get my worry ( I am too much but, I am worried) Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318563 Share on other sites More sharing options...
MadTechie Posted August 8, 2007 Share Posted August 8, 2007 $_FILES['MyFiles']['tmp_name'] Is the temporary filename of the file in which the uploaded file was stored on the server. this will have a name like "/var/tmp/phpie5H7A" and will should be unique, as the server sets this name for you.. the problem will be the $target_path name.. as this will be the name of the file being uploaded.. so if 2 members upload "myFile.doc" then the last one will over write the previous file.. you can get around this by prefixing the users name/id. ie $target_path = $base_path . basename( $_FILES['MyFiles']['name'][$FN]); to $UserName = 10;//the username or id. $target_path = $base_path.$UserName."_".basename( $_FILES['MyFiles']['name'][$FN]); Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318571 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 I don't know that I have to use target path! I only use the following which sits in a for loop move_uploaded_file($_FILES["file".$i]["tmp_name"],"../../Photos/" .$_FILES["file".$i]["name"]); can you write me the target path code for me, but all my files for a particular person will go to a unique folder ( this folder is sitting aling with my other folders) by the way my php info says "upload_tmp_dir" = "no value" must it set a value. my work is fine even with this setting Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318580 Share on other sites More sharing options...
MadTechie Posted August 8, 2007 Share Posted August 8, 2007 for the script i posted the base_path would have to be $base_path = "../../Photos/"; to fit your upload if thats what you were asking Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318585 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 one sec, i am trying Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318594 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 I failed! Will you be kind do some twitch to my code, don't any thing major, thanks. //Make New Folder mkdir("../../Photos/".$RandomKey); //Upload Files for ($i=0; $i<=$MaxFileCount; $i++) { if (!($_FILES["file".$i]["name"]=="")) { if ($_FILES["file".$i]["error"] > 0) { $UploadFileReadyFlag=2; echo "<br />File Error Return Code: " . $_FILES["file".$i]["error"] . "<br /><br />"; } else { /*Photo Uploads*/ { $FileCount=$FileCount+1; move_uploaded_file($_FILES["file".$i]["tmp_name"],"../../Photos/".$RandomKey."/" .$_FILES["file".$i]["name"]); rename("../../Photos/".$RandomKey."/" .$_FILES["file".$i]["name"],"../../Photos/".$RandomKey."/" .$UploadFileNameLeader.$FileCount.".jpg"); /*Check for Width & Height*/ list($width, $height)=getimagesize("../../Photos/".$RandomKey."/" .$UploadFileNameLeader.$FileCount.".jpg"); if (($width>100)||($height>100)) { $UploadFileReadyFlag=2; echo "File (".$_FILES["file".$i]["name"].") - Is ( ".$width." Width X ".$height." Heigth ) Pixels!<br />"; } } } } } Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318604 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 PHPinfo says upload_tmp_dir = no value . must I set any value for this Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318625 Share on other sites More sharing options...
MadTechie Posted August 8, 2007 Share Posted August 8, 2007 heres a little update. what are the errors ? maybe try changing it to upload_tmp_dir = "c:/temp/php/uploads/" (what ever the upload path is) your need to restart apache <?php echo "<pre>"; print_r($_FILES); //Make New Folder $baseFolder = "../../Photos/".$RandomKey; mkdir($baseFolder); chmod($baseFolder, 0777); //Upload Files for ($i=0; $i<=$MaxFileCount; $i++) { if ($_FILES["file".$i]["name"]!="") { if ($_FILES["file".$i]["error"] > 0) { $UploadFileReadyFlag=2; echo "<br />File Error Return Code: " . $_FILES["file".$i]["error"] . "<br /><br />"; } else { $FileCount=$FileCount+1; move_uploaded_file($_FILES["file".$i]["tmp_name"],$baseFolder."/" .$_FILES["file".$i]["name"]); rename($baseFolder."/" .$_FILES["file".$i]["name"],$baseFolder.$UploadFileNameLeader.$FileCount.".jpg"); /*Check for Width & Height*/ list($width, $height)=getimagesize($baseFolder."/" .$UploadFileNameLeader.$FileCount.".jpg"); if (($width>100)||($height>100)) { $UploadFileReadyFlag=2; echo "File (".$_FILES["file".$i]["name"].") - Is ( ".$width." Width X ".$height." Heigth ) Pixels!<br />"; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318629 Share on other sites More sharing options...
oceans Posted August 8, 2007 Author Share Posted August 8, 2007 Friend, I am very pleased that you did a code for me, it is very late into night, I will try tom morning and give you the via PM . thanks buddy my eyes are heavy.. Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-318637 Share on other sites More sharing options...
jitesh Posted August 9, 2007 Share Posted August 9, 2007 I am worried what will happen if two concurrent user uploads files will the file get mixed up? files will mixed up ? Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-319092 Share on other sites More sharing options...
jitesh Posted August 9, 2007 Share Posted August 9, 2007 No need to think and worry. because tmp_name will be diffenent each time at each request. Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-319110 Share on other sites More sharing options...
oceans Posted October 24, 2007 Author Share Posted October 24, 2007 Dear people, I have one more issue here. When someone selects a file using the browse button (this will lead to a file select dialog), things work fine! BUT When someone types in a rubbish value say “abcd” at the field beside this browse button (left), the page hangs! But I can get an error message, if I typed in rubbish value in the file select window which come after clicking the browse button. (This happens for single or multiple conurrent uploads) Can anyone help me to overcome this, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-376702 Share on other sites More sharing options...
oceans Posted October 24, 2007 Author Share Posted October 24, 2007 Any one wish to comment, please. Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-376844 Share on other sites More sharing options...
MadTechie Posted October 24, 2007 Share Posted October 24, 2007 can you post your latest code Quote Link to comment https://forums.phpfreaks.com/topic/63912-concurrent-uploads/#findComment-376948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.