您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP把图片上传到又拍云

2024/3/10 3:40:41发布28次查看
注意:网站使用cdn上的图片有利有减轻网站的压力,同时也要注意在本地存一份同路径的图片,当云盘有问题时,可以马上切换到本地来访问。
    /* 在原有的编辑器基础上增加图片上传到cdn的功能*/
    header(content-type: text/html; charset=utf-8);
error_reporting( e_error | e_warning );
$path = ./images/;    /* 设置文件的存储路径 */
$ymd = date(y).date(m).date(d);  //文件路径格式
$file_save_url=$path.$ymd./;   //本地存储路径
$save_url= $ymd. /;     //优盘云存储路径
include upyun.class.php;//引入优盘云处理类
include upyun_config.php;//优盘云配置
//实例化优盘云
    $upyun = new upyun($img_bucketname, $img_username, $img_password);
try {
$file=$file_save_url.$info['name'];// 本地路径加文件名
$con =$save_url.$info['name'];//优盘云路径加文件名
$opts = array(  upyun::content_md5 => md5(file_get_contents($file)) );
$fh = fopen($file, rb);
// 上传图片,自动创建目录
        $rsp = $upyun->writefile(/.$con, $fh, true, $opts);
fclose($fh);
} catch(exception $e) {
$filename = error_log.txt;
$errorcontent = image  . date(y-m-d h:m:s) .   . $e->getcode().  . $e->getmessage() . \r\n;
$handle = fopen($filename, 'a');
fwrite($handle, $errorcontent);
fclose($handle);
exit;
} 原文链接:http://www.lujianlong.com/?p=260
upyun.rar ( 4.56 kb 下载:4 次 )
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product