Home > Backend Development > PHP Tutorial > 关于CURL上传问题

关于CURL上传问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:36:26
Original
1131 people have browsed it

<code>php</code><code><?php $ch = curl_init();
    $data = array('name' => 'Foo', 'file' => new \CURLFile(realpath('1.jpg'))); //绝对路径
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/post.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
?>
</code>
Copy after login
Copy after login

假设我要上传的文件来自网络
网络文件图片URL如下:http://7sbpxj.com1.z0.glb.clouddn.com/firstpage
我file = “网络文件”
那么该怎么写

回复内容:

<code>php</code><code><?php $ch = curl_init();
    $data = array('name' => 'Foo', 'file' => new \CURLFile(realpath('1.jpg'))); //绝对路径
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/post.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
?>
</code>
Copy after login
Copy after login

假设我要上传的文件来自网络
网络文件图片URL如下:http://7sbpxj.com1.z0.glb.clouddn.com/firstpage
我file = “网络文件”
那么该怎么写

直接在post.php下载远程文件
<br> $file=file_get_contents($_POST['file']);<br> file_put_contents($file, $temp);<br>

直接上代码吧;

CURL上传图片完整版

如果post.php支持网络文件,应该把地址给它就行,或者就先下载到本地文件吧。

CURLFile 印象中是不能写网络图片URL的吧
所以你还是自己下载下来再POST

<code>php</code><code>couldn't open file "http://7sbpxj.com1.z0.glb.clouddn.com/firstpage"
</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template