使用curl将图片从目录上传到外部网站 [英] Upload image from directory to external site using curl

查看:126
本文介绍了使用curl将图片从目录上传到外部网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ok我想知道是否可以使用curl并从我的网站目录而不是我的机器上传图像
我需要做的是从我的图像目录中上传一个图像使用文件 - 选择一种形式,如果任何人知道我需要编辑在我的代码我会喜欢它,我已经看过网络,但没有发现在我的搜索,我想我需要文件获取内容base64编码然后post am我正在思考这个?

Ok i was wondering if it is possible to use curl and upload a image from my sites directory rather then off my machine, what i need to do exactly is upload a image from my image directory using the file-select in a form, If anyone knows what i need to edit in my code i would appreciate it, i have looked across the web but found nothing in my search, I was thinking that i would need to file get content base64 encode then post am i right in thinking this?

$upload_url = 'http://example.com/settings/upload-img';
$file_path = 'directory/image.png';
$fields = array(
   "MAX_FILE_SIZE" => "",
   "fileselect[]" => $file_path
);

foreach ($fields as $key => $val) {
   $post_data .= $key . '=' . $val . '&';
}

$chr = curl_init();
curl_setopt($chr, CURLOPT_URL, $upload_url);
curl_setopt($chr,CURLOPT_POST, count($fields));
curl_setopt($chr,CURLOPT_POSTFIELDS, rtrim($post_data, '&'));
curl_setopt($chr, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($chr);
curl_close($chr);

我对base64_encode()的映像的想法如下,正确的想法这可能工作。

What I had in mind for the image to base64_encode() is below, I am not sure if I am correct thinking this may work.

$raw_img = base64_encode(file_get_contents('directory/image.png'));

然后使用fileselect []=> $ raw_img

Then use "fileselect[]" => $raw_img

推荐答案

<?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",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);
?>

看起来很多人想知道什么是_VIRUS_SCAN_URL?

It seems that many want to know what is _VIRUS_SCAN_URL?

它是开发人员的新主机病毒扫描。

Its the new host virus scanning for developers. Internally all the files sent to Virus Scanning Module to check any virus to cause damage to Server or not.

http://virusade.com ,但仍处于测试模式,_VIRUS_SCAN_URL和@ there api PROTOCAL。

Service is developed by http://virusade.com but it is still in beta mode and _VIRUS_SCAN_URL and @ there api PROTOCAL.

只要他们从服务器获取文档扫描它,如果非病毒,然后将其发送到上传服务器。

Simply they fetch the document from the server scans it and if non-virus then sends it to the uploading server.

这篇关于使用curl将图片从目录上传到外部网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆