通过curl上传文件
我尝试在php中通过curl上传文件, 这是我的示例代码,
set_time_limit(0);
$url = 'http://localhost/curltest/upload.php';
$field_name = 'file';
if (isset($_FILES['file']))
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_POSTFIELDS,array("$field_name"=>"@".$_FILES['file']['tmp_name']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
我将权限设置为 777,但它不起作用。 问题出在哪里? (它没有显示任何结果)
I try to upload file via curl in php,
this is my sample code
set_time_limit(0);
$url = 'http://localhost/curltest/upload.php';
$field_name = 'file';
if (isset($_FILES['file']))
{
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_POSTFIELDS,array("$field_name"=>"@".$_FILES['file']['tmp_name']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
I set permission to 777,but it doesn't work.
where is the problem?
(it doesn't show any result)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里有一个问题:
$_FILES['file'['tmp_name']
它应该是$_FILES['file']['tmp_name']
或其他东西像这样。你忘记关闭 ['file' 括号I think there is a problem here :
$_FILES['file'['tmp_name']
it should be$_FILES['file']['tmp_name']
or something like this. You forget to close the ['file' bracket