Dan06 Posted March 16, 2009 Share Posted March 16, 2009 I'm having trouble uploading multiple files at the same time. For example, if I send two files at the same time, the first file is uploaded but the second is seemingly ignored. I don't know if the problem is with the request entity or the php code. Does anyone know which is the problem? Thanks. Below is the "Request Entity" that is submitted to the server: --3D6atZKLBPujpCZzClN-wz3AJ0Eh-BBWlRr Content-Disposition: form-data; name="imgFile[]"; filename="Inbox_Msg_Display.GIF" Content-Type: application/octet-stream; charset=ISO-8859-1 Content-Transfer-Encoding: binary --3D6atZKLBPujpCZzClN-wz3AJ0Eh-BBWlRr-- --A2cG-IXHLNC2Rk7kF3fQ5-bQPQpuDwmUU Content-Disposition: form-data; name="imgFile[]"; filename="Table_Msg_Content.GIF" Content-Type: application/octet-stream; charset=ISO-8859-1 Content-Transfer-Encoding: binary --A2cG-IXHLNC2Rk7kF3fQ5-bQPQpuDwmUU-- Following is the code I'm using to process the request entity: for ($i = 0; $i < count($_FILES['imgFile']); $i++){ $targetPath = "profile_images/"; $targetPath = $targetPath . basename($_FILES['imgFile']['name'][$i]); move_uploaded_file($_FILES['imgFile']['tmp_name'][$i], $targetPath); } Quote Link to comment https://forums.phpfreaks.com/topic/149668-uploading-multiple-files-request-entity-or-php-issue/ Share on other sites More sharing options...
Marco000 Posted March 16, 2009 Share Posted March 16, 2009 Try the following code, for ($i = 0; $i < count($_FILES['imgFile']['name']); $i++){ $targetPath = "profile_images/"; $targetPath = $targetPath . basename($_FILES['imgFile']['name'][$i]); move_uploaded_file($_FILES['imgFile']['tmp_name'][$i], $targetPath); } Because if you upload multipull images the array looks like Array ( [pictures] => Array ( [name] => Array ( [0] => Image1.jpg [1] => Image2.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => C:\xampp\tmp\phpBCCB.tmp [1] => C:\xampp\tmp\phpBCCC.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 33227 [1] => 28680 ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/149668-uploading-multiple-files-request-entity-or-php-issue/#findComment-786048 Share on other sites More sharing options...
Dan06 Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks for the suggestion; I tried it but it didn't solve the problem. To figure out the problem, I printed the array, below is the result: Array ( [name] => Array ( [0] => Inbox_Msg_Display.GIF ) [type] => Array ( [0] => application/octet-stream ) [tmp_name] => Array ( [0] => C:\WINDOWS\Temp\php1A3.tmp ) [error] => Array ( [0] => 0 ) => Array ( [0] => 55250 ) ) Based on the above, my guess is the problem is the request entity. Anyone have anymore suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/149668-uploading-multiple-files-request-entity-or-php-issue/#findComment-786116 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.