国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP7基于curl實現的上傳圖片功能php技巧

2020-03-22 18:38:23
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了PHP7基于curl實現的上傳圖片功能,結合實例形式對比分析了php5.5之前與php7版本的curl圖片上傳功能相關實現與使用技巧,需要的朋友可以參考下

本文實例講述了PHP7基于curl實現的上傳圖片功能。分享給大家供大家參考,具體如下:

根據php版本不同,curl模擬表單上傳的方法不同

php5.5之前

$curl = curl_init();if (defined( CURLOPT_SAFE_UPLOAD )) { curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);$data = array( file = @ . realpath($path));//‘@ 符號告訴服務器為上傳資源curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_POST, 1 );curl_setopt($curl, CURLOPT_POSTFIELDS, $data);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_USERAGENT, TEST $result = curl_exec($curl);$error = curl_error($curl);

php5.5之后,到php7

$curl = curl_init();curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);$data = array( file = new /CURLFile(realpath($path)));url_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_POST, 1 );curl_setopt($curl, CURLOPT_POSTFIELDS, $data);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_USERAGENT, TEST $result = curl_exec($curl);$error = curl_error($curl);

下面提供一個兼容的方法:

$curl = curl_init();if (html' target='_blank'>class_exists( /CURLFile )) { curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);$data = array( file = new /CURLFile(realpath($path)));// =5.5} else { if (defined( CURLOPT_SAFE_UPLOAD )) { curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false); $data = array( file = @ . realpath($path));// =5.5curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_POST, 1 );curl_setopt($curl, CURLOPT_POSTFIELDS, $data);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_USERAGENT, TEST $result = curl_exec($curl);$error = curl_error($curl);

其中:

$path:為待上傳的圖片地址

$url:目標服務器地址

例如

$url= http://localhost/upload.php $path = /bg_right.jpg 

upload.php示例:

 ?php file_put_contents(time(). .json , json_encode($_FILES)); $tmp_name = $_FILES[ file ][ tmp_name  $name = $_FILES[ file ][ name  move_uploaded_file($tmp_name, audit/ .$name);? 

您可能感興趣的文章:

PHP5.0~5.6 各版本兼容性cURL文件上傳功能實例分析php技巧

PHP區塊查詢實現方法分析php技巧

可兼容php5與php7的cURL文件上傳功能實例分析php技巧

以上就是PHP7基于curl實現的上傳圖片功能php技巧的詳細內容,PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宽甸| 原阳县| 济南市| 腾冲县| 阿图什市| 望奎县| 沙田区| 武山县| 定陶县| 城步| 专栏| 大名县| 临海市| 凌源市| 文成县| 荥阳市| 桐庐县| 青州市| 新丰县| 望江县| 遂平县| 剑河县| 黑龙江省| 奎屯市| 澳门| 兴仁县| 永德县| 瓦房店市| 马鞍山市| 余姚市| 金秀| 安吉县| 桃园市| 青河县| 绥宁县| 桐乡市| 康平县| 邹平县| 重庆市| 万山特区| 丰县|