当前位置 : 主页 > 网络编程 > PHP >

curl上传图片至sm.ms

来源:互联网 收集:自由互联 发布时间:2021-06-30
上传图片至https://sm.ms/,详见:http://blog.skyx.in/archives/164/ 1. [代码] [PHP]代码 ?php$url = 'https://sm.ms/index.php?act=upload';$image = curl_file_create(realpath('test.jpg'), 'image/jpg', 'test.jpg'); $ch = curl_init();c
上传图片至https://sm.ms/,详见: http://blog.skyx.in/archives/164/

1. [代码][PHP]代码    

<?php
$url = 'https://sm.ms/index.php?act=upload';
$image = curl_file_create(realpath('test.jpg'), 'image/jpg', 'test.jpg');
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['smfile' => $image]);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
网友评论