标签归档:PHP

IIS7.5/PHPv5.3.24 DiscuzX2.5上传文件出现Upload Error: 500的解决方法

添加了临时目录,重启IIS服务器后终于解决了。

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir =C:\phpfileuploadtmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 24M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

PHP下载远程图片的函数


/**
 * 抓取远程图片
 *
 * @param string $url 远程图片路径
 * @param string $filename 本地存储文件名
 **/
 
$url = $_POST['url']; 
$tid = $_POST['tid'];

if(!empty($url) && !empty($tid)){
	
	if(grabImage($url,$tid,'')){
		
		echo '成功了!' ;
	}else{
		
		echo '失败了!' ;
	}
	
}
 
function grabImage($url, $tid, $filename = '') {
    if($url == '') {
        return false; //如果 $url 为空则返回 false;
    }
    $ext_name = strrchr($url, '.'); //获取图片的扩展名
    if($ext_name != '.gif' && $ext_name != '.jpg' && $ext_name != '.bmp' && $ext_name != '.png') {
        return false; //格式不在允许的范围
    }
    if($filename == '') {
        $filename = $tid.$ext_name; //以时间戳另起名
    }
    //开始捕获
    ob_start();
    readfile($url);
    $img_data = ob_get_contents();
    ob_end_clean();
    $size = strlen($img_data);
    $local_file = fopen($filename , 'a');
    fwrite($local_file, $img_data);
    fclose($local_file);
    return $filename

}