0
アップロードしたいファイル(画像)をいくつか投稿しようとしているときに問題が発生しています。 PHP 5.3.3およびCURL 7.20.0の使用PHPとcURLで画像をアップロード
ここにphpスクリプトがあります(画像は、パスが有効であることを確認した同じフォルダにあります)。
function curl_post_request($url, $data, $referer='') {
$data = http_build_query($data); // seems to be required arrays should'nt be supported ? whatever.
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_REFERER, $referer);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($c, CURLOPT_HEADER, $headers);
curl_setopt($c, CURLINFO_HEADER_OUT, true);
curl_setopt($c, CURLOPT_VERBOSE, true);
$output = curl_exec($c);
var_dump(curl_getinfo($c, CURLINFO_HEADER_OUT));
//var_dump($data);
if($output === false) trigger_error('Erreur curl : '.curl_error($c),E_USER_WARNING);
curl_close($c);
return $output;
}
if(isset($_GET['GO'])) {
$data = array(
'pic1' => "@".realpath('image.jpg'),
'postedvar1' => 'test1',
'postedvar2' => 'test2'
);
$url = 'http://localhost/test/index.php';
$a = curl_post_request($url, $data);
var_dump($a);
} else {
print_r($_POST);
print_r($_FILES);
}
私は何が欠けていますか?これはあなたのために働いていますか?カール要求は以下の結果を見てみましょう、罰金のようです
:アップロードするファイルを指定する@filepath
方法を使用するには
headers = POST /test/test.php HTTP/1.1 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 Host: localhost Accept: */* Referer: Content-Length: 82 Content-Type: application/x-www-form-urlencoded HTTP/1.1 200 OK Date: Sun, 11 Sep 2011 19:46:18 GMT Server: Apache/2.2.16 (Win32) PHP/5.3.3 X-Powered-By: PHP/5.3.3 Content-Length: 138 Content-Type: text/html $_POST = Array( [pic1] => @C:\wamp\www\test\image.jpg [postedvar1] => test1 [postedvar2] => test2 ) $_FILES = Array()
何のエラーを得るのですか? 'curl_error()'から何か? –
$ _POSTはOKですが、$ _FILESは空です! arobaseはリクエストに影響を与えないようです。要求はファイルなしで正常に進むようです! –
「質問は解決されました!」と質問をしないでください。 - StackOverflowは、将来のためのリソースであり、今あなたを助けることを意図しています。 – salathe