2012-11-23 59 views
1

我要发布的一些数据,包括image.I正在使用curl在PHP的this.My代码如下─错误的图片上传

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data")); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0Mozilla/4.0 (compatible;)"); 
    curl_setopt($ch, CURLOPT_URL, 'http://postacity.co.uk:8080/shine/pp/upload/'); 
    curl_setopt($ch, CURLOPT_POST, true); 
    $post = array(
     'creatorid' => '119', 
     'userfile' => '@/temp/fgf.jpg', 
     'notice' => 'Image1', 
     'catid' => '1', 
     'title' => 'bookofzeus', 
     'boardid' => '332', 
    ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch); 
    if(curl_errno($ch)) { 
     echo 'Error: ' . curl_error($ch); 
    } 
    else { 
     echo $response; 
    } 
    } 

每次我收到了同样的错误

Error: failed creating formpost data

我在做任何错误。我已经找到了这个问题,但仍然没有找到解决办法。

回答

1

请参阅本公司工作

<?php 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); 
    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL); 
    curl_setopt($ch, CURLOPT_POST, true); 
    // same as <input type="file" name="file_box"> 
    $post = array(
     "file_box"=>"@/path/to/myfile.jpg", 
     "username"=>"foobar", 
     "password"=>"secret", 
     "submit"=>"submit" 
    ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch); 
?> 

也可参考这个网址的

http://joshhighland.com/blog/2010/11/27/using-curl-and-php-to-upload-files-through-a-form-post/

http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/