PHP - Upload an image file to other domain with CURL

后端 未结 4 1278
孤城傲影
孤城傲影 2020-12-10 08:09

I have two domain, as example site1.loc and site2.loc. In site1.loc i have a php form file like this:

<         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 08:41

    The way you are doing it right now won't work because your server does not send the file to the remote server but the local filename (from the user). Also to transfer a file via CURL you need to add a '@' before the name.

    $c_pic = '@'. $_FILES['c_pic']['tmp_name']
    

    Then the remote script also has to get the file from the $_FILES variable and copy it somewhere with move_uploaded_file (PHP.net)

    Also a tip: check $_FILES['c_pic']['error'] before doing this to prevent uploading garbage to the remote server.

提交回复
热议问题