Multiple file uploads with cURL

前端 未结 2 884
死守一世寂寞
死守一世寂寞 2021-01-18 23:09

I\'m using cURL to transfer image files from one server to another using PHP. This is my cURL code:

// Transfer the original image and thumbnail to our stora         


        
相关标签:
2条回答
  • 2021-01-19 00:07

    The code itself looks ok, but I don't know about your move() target directory. You're using the raw filename as provided by the client (which is your curl script). You're using the original uploaded filename (as specified in your curl script) as the target of the move, with no overwrite checking and no path data. If the two uploaded files have the same filename, you'll overwrite the first processed image with whichever one got processed second by PHP.

    Try putting some debugging around the move() command:

    if (!move_uploaded_file($_FILES['upload']['tmp_name'][$key], $_FILES['upload']['name'][$key])) {
       echo "Unable to move $key/";
       echo $_FILES['upload']['tmp_name'][$key];
       echo ' to ';
       echo $_FILES['upload']['name'][$key];
    }
    

    (I split the echo onto multiple lines for legibility).

    0 讨论(0)
  • 2021-01-19 00:13

    here is your error in the curl call...

    var_dump($post)
    

    you are clobbering the array entries of your $post array since the key strings are identical...

    make this change

    $post = array(
        'upload[0]' => '@' . $tmp_uploads . $filename,
        'upload[1]' => '@' . $tmp_uploads . $thumbname,
        'salt' => 'q8;EmT(Vx*Aa`fkHX:up^WD^^b#<Lm:Q'
    );
    
    0 讨论(0)
提交回复
热议问题