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)
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