Note: Using images on a CDN will help reduce the pressure on the website. At the same time, you should also pay attention to saving a copy of the image with the same path locally. When there is a problem with the cloud disk, you can immediately switch to the local for access./* Based on the original editor, add the function of uploading pictures to cdn*/
Header("Content-Type: text/html; charset=utf-8");
error_reporting(E_ERROR | E_WARNING);
$Path = "./images/"; /* Set the storage path of the file */
$ymd = date("Y").date("m").date("d"); //File path format
$file_save_url=$Path.$ymd."/"; //Local storage path
$save_url= $ymd. "/"; //USB cloud storage path
Include "upyun.class.php";//Introducing the USB cloud processing class
Include "upyun_config.php";//USB cloud configuration
//Instantiate USB Cloud
$upyun = new UpYun($img_bucketname, $img_username, $img_password);
Try {
$file=$file_save_url.$info['name'];//Local path plus file name
$con =$save_url.$info['name'];//USB cloud path plus file name
$opts = array( UpYun::CONTENT_MD5 => md5(file_get_contents($file)));
$fh = fopen($file, "rb");
// Upload pictures and automatically create directories
$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() . "rn";
$handle = fopen($filename, 'a');
fwrite($handle, $errorcontent);
fclose($handle);
exit;
}
Original link: http://www.lujianlong.com/?p=260
upyun.rar( 4.56 KB Download: 4 times )