CURL PHP 发送图像 [英] CURL PHP send image

查看:34
本文介绍了CURL PHP 发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从服务器获取图像很简单,但我想到了一些不同的东西.这是一个疯狂的问题,但是...是否可以将文件(图像)发送到服务器但不使用表单上传或 ftp 连接?我想向例如发送请求.http://www.example.com/file.php 带有二进制内容.我想我需要设置 Content-type 标题图像/jpeg 但如何向我的请求添加一些内容?

It's trivial to get image from server but I think about something different. It is crazy question but... Is it possible to send file (image) to a server but not using form upload or ftp connection? I want to send a request to eg. http://www.example.com/file.php with binary content. I think I need to set Content-type header image/jpeg but how to add some content to my request?

推荐答案

使用curl上传图片文件有多种方式,例如:

there are multiple ways to use curl to upload image files, e.g.:

$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/path/to/image.jpeg');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
//CURLOPT_SAFE_UPLOAD defaulted to true in 5.6.0
//So next line is required as of php >= 5.6.0
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);

您可以在以下位置查看示例:http://au.php.net/manual/en/function.curl-setopt.php

you can check the examples at: http://au.php.net/manual/en/function.curl-setopt.php

这篇关于CURL PHP 发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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