Jump to content

Uploading multiple files - request entity or php issue?


Dan06

Recommended Posts

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);
}

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
                )

        )

)

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.