简体   繁体   English

使用curl / php上传图片

[英]Picture uploading using curl/php

I am trying to upload image using php/curl on a website using curl/php. 我正在尝试使用curl / php在网站上使用php / curl上传图像。 The website uses ajax/flash to upload images to external server. 该网站使用ajax / flash将图像上传到外部服务器。 When I upload an image manually on the website, using firebug, I just receive the response (with permanent link) if the image is successfully uploaded but I don't see what parameters and data were posted and where exactly. 当我使用Firebug在网站上手动上传图像时,如果图像成功上传,我只会收到响应(带有永久链接),但是看不到张贴了哪些参数和数据以及确切位置。

web url where image needs to be uploaded: 需要上传图片的网址:

http://tinyurl.com/bp779wx http://tinyurl.com/bp779wx

How do I find out what parameters need to be sent in order to get the image uploaded successfully on the website? 如何确定需要发送哪些参数才能使图像成功上传到网站上?

The specific uploader you have mentioned extracts the epsToken variable from the following URL, then uses it as a parameter to upload the file. 您提到的特定上载器从以下URL中提取epsToken变量,然后将其用作参数来上载文件。

http://johannesburg.gumtree.co.za/c-GetEpsToken http://johannesburg.gumtree.co.za/c-GetEpsToken

In my case, the token was: 就我而言,令牌是:

1:b6ac30fa715a395cf728ac29847b2516f701a8f291fd5243d5153eae41c10636 1:b6ac30fa715a395cf728ac29847b2516f701a8f291fd5243d5153eae41c10636

You can see the full POST data for the upload request I made here . 您可以看到我在此处提出的上传请求的完整POST数据。 Keep in mind that this is a multipart/form-data request so you may need to adjust your curl/PHP code to support that. 请记住,这是一个多部分/表单数据请求,因此您可能需要调整curl / PHP代码以支持该请求。

Basically, the following parameters were supplied via the POST request: 基本上,以下参数是通过POST请求提供的:

Filename = Image.png 
b = 18 
s = 1C5000 
n = k 
a = 1:b6ac30fa715a395cf728ac29847b2516f701a8f291fd5243d5153eae41c10636
v = k 
r = 0 
u = the actual image, sent as a multipart stream 
Upload = Submit Query

I suggest you analyse the other parameters and use the code from the other answers in order to successfully upload the image. 建议您分析其他参数,并使用其他答案中的代码来成功上传图像。

Upload image with PHP and cURL. 使用PHP和cURL上传图像。

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

Upload image using CURL + PHP via remote form 使用CURL + PHP通过远程表单上传图像

 $info = array('test title','1234','virginia','@'.realpath('e:\wamp  
 \www\1.jpg'),'@'.realpath('e:\wamp\www\2.jpg'),'@'.realpath('e:\wamp\www
 \3.jpg'),'@'.realpath('e:\wamp\www\4.jpg'),'test description');
  $post->postAd($url, $info);

Also Please read this 还请阅读此

http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/ http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/

And see this link 并查看此链接

http://blog.smileylover.com/remote-upload-to-imageshackus-with-phpcurl/ http://blog.smileylover.com/remote-upload-to-imageshackus-with-phpcurl/

And

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

Some problem with the site's image uploaded - it just pops up an error 网站图片上传时出现了一些问题-它只是弹出一个错误

There was an error uploading your picture. 上传您的图片时出错。 Please check the image size and dimension and try again. 请检查图像的尺寸和尺寸,然后重试。 If you continue to have issues, you can switch to the basic image loader. 如果仍然有问题,可以切换到基本图像加载器。

for every type of images and basic image loader is also not actually available!. 对于每种类型的图像,基本的图像加载器实际上也无法使用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM