1. <legend id='vnBq9'><style id='vnBq9'><dir id='vnBq9'><q id='vnBq9'></q></dir></style></legend>
        • <bdo id='vnBq9'></bdo><ul id='vnBq9'></ul>

        <i id='vnBq9'><tr id='vnBq9'><dt id='vnBq9'><q id='vnBq9'><span id='vnBq9'><b id='vnBq9'><form id='vnBq9'><ins id='vnBq9'></ins><ul id='vnBq9'></ul><sub id='vnBq9'></sub></form><legend id='vnBq9'></legend><bdo id='vnBq9'><pre id='vnBq9'><center id='vnBq9'></center></pre></bdo></b><th id='vnBq9'></th></span></q></dt></tr></i><div id='vnBq9'><tfoot id='vnBq9'></tfoot><dl id='vnBq9'><fieldset id='vnBq9'></fieldset></dl></div>

        <small id='vnBq9'></small><noframes id='vnBq9'>

      2. <tfoot id='vnBq9'></tfoot>

        如何使用 curl 和 PHP 上传文件

        how to upload file using curl with PHP(如何使用 curl 和 PHP 上传文件)

      3. <i id='fs5b9'><tr id='fs5b9'><dt id='fs5b9'><q id='fs5b9'><span id='fs5b9'><b id='fs5b9'><form id='fs5b9'><ins id='fs5b9'></ins><ul id='fs5b9'></ul><sub id='fs5b9'></sub></form><legend id='fs5b9'></legend><bdo id='fs5b9'><pre id='fs5b9'><center id='fs5b9'></center></pre></bdo></b><th id='fs5b9'></th></span></q></dt></tr></i><div id='fs5b9'><tfoot id='fs5b9'></tfoot><dl id='fs5b9'><fieldset id='fs5b9'></fieldset></dl></div>
          <legend id='fs5b9'><style id='fs5b9'><dir id='fs5b9'><q id='fs5b9'></q></dir></style></legend>
          <tfoot id='fs5b9'></tfoot>

          <small id='fs5b9'></small><noframes id='fs5b9'>

          • <bdo id='fs5b9'></bdo><ul id='fs5b9'></ul>
              <tbody id='fs5b9'></tbody>

                1. 本文介绍了如何使用 curl 和 PHP 上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道如何使用 cURL 或 PHP 中的任何其他方式上传文件.google了很多遍都没有结果.

                  I want to know how to upload file using cURL or anything else in PHP. I have searched in google many times but no results.

                  换句话说,用户在表单上看到一个文件上传按钮,该表单被发布到我的 php 脚本,然后我的 php 脚本需要将其重新发布到另一个脚本(例如在另一个服务器上).

                  In other words, the user sees a file upload button on a form, the form gets posted to my php script, then my php script needs to re-post it to another script (eg on another server).

                  我有这个代码来接收文件并上传它

                  I have this code to receive the file and upload it

                  代码:

                  echo"".$_FILES['userfile']."";
                  $uploaddir = './';
                  $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
                  if ( isset($_FILES["userfile"]) ) {
                      echo '<p><font color="#00FF00" size="7">Uploaded</font></p>';
                      if (move_uploaded_file
                  ($_FILES["userfile"]["tmp_name"], $uploadfile))
                  echo $uploadfile;
                      else echo '<p><font color="#FF0000" size="7">Failed</font></p>';
                  }
                  

                  我希望代码将文件发送到接收文件.

                  I want the code to send the file to receiver file.

                  推荐答案

                  使用:

                  if (function_exists('curl_file_create')) { // php 5.5+
                    $cFile = curl_file_create($file_name_with_full_path);
                  } else { // 
                    $cFile = '@' . realpath($file_name_with_full_path);
                  }
                  $post = array('extra_info' => '123456','file_contents'=> $cFile);
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$target_url);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
                  $result=curl_exec ($ch);
                  curl_close ($ch);
                  

                  也可以参考:

                  http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/

                  PHP 5.5+ 的重要提示:

                  现在我们应该使用 https://wiki.php.net/rfc/curl-file-upload 但如果您仍想使用这种已弃用的方法,则需要设置 curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

                  Now we should use https://wiki.php.net/rfc/curl-file-upload but if you still want to use this deprecated approach then you need to set curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

                  这篇关于如何使用 curl 和 PHP 上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                2. <small id='8ym7p'></small><noframes id='8ym7p'>

                      <tbody id='8ym7p'></tbody>
                      <legend id='8ym7p'><style id='8ym7p'><dir id='8ym7p'><q id='8ym7p'></q></dir></style></legend>
                      • <tfoot id='8ym7p'></tfoot>

                          <bdo id='8ym7p'></bdo><ul id='8ym7p'></ul>
                            <i id='8ym7p'><tr id='8ym7p'><dt id='8ym7p'><q id='8ym7p'><span id='8ym7p'><b id='8ym7p'><form id='8ym7p'><ins id='8ym7p'></ins><ul id='8ym7p'></ul><sub id='8ym7p'></sub></form><legend id='8ym7p'></legend><bdo id='8ym7p'><pre id='8ym7p'><center id='8ym7p'></center></pre></bdo></b><th id='8ym7p'></th></span></q></dt></tr></i><div id='8ym7p'><tfoot id='8ym7p'></tfoot><dl id='8ym7p'><fieldset id='8ym7p'></fieldset></dl></div>