作者:dingzhi521 | 来源:互联网 | 2018-03-22 15:40
更改xhEditor 上传文件upload.php
把上传完的图片路径改为 http 路径
PHP代码
$maxAttachSize)$err='请不要上传大小超过'.formatBytes($maxAttachSize).'的文件';
else
{
switch($dirType)
{
case 1: $attachSubDir = 'day_'.date('ymd'); break;
case 2: $attachSubDir = 'month_'.date('ym'); break;
case 3: $attachSubDir = 'ext_'.$extension; break;
}
$attachDir = $attachDir.'/'.$attachSubDir;
if(!is_dir($attachDir))
{
@mkdir($attachDir, 0777);
@fclose(fopen($attachDir.'/index.htm', 'w'));
}
PHP_VERSION <&#39;4.2.0&#39; && mt_srand((double)microtime() * 1000000);
$newFilename=date("YmdHis").mt_rand(1000,9999).&#39;.&#39;.$extension;
$targetPath = $attachDir.&#39;/&#39;.$newFilename;
rename($tempPath,$targetPath);
@chmod($targetPath,0755);
$targetPath=jsonString($targetPath);
if($immediate==&#39;1&#39;)$targetPath=&#39;!&#39;.$targetPath;
if($msgType==1)$msg="&#39;$targetPath&#39;";
else $msg="{&#39;url&#39;:&#39;".$dir_url_http.$targetPath."&#39;,&#39;localname&#39;:&#39;".jsonString($localName)."&#39;,&#39;id&#39;:&#39;1&#39;}";//id参数固定不变,仅供演示,实际项目中可以是数据库ID
}
}
else $err=&#39;上传文件扩展名必需为:&#39;.$upExt;
@unlink($tempPath);
}
echo "{&#39;err&#39;:&#39;".jsonString($err)."&#39;,&#39;msg&#39;:".$msg."}";
function jsonString($str)
{
return preg_replace("/([\\\\\/&#39;])/",&#39;\\\$1&#39;,$str);
}
function formatBytes($bytes) {
if($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . &#39;GB&#39;;
} elseif($bytes >= 1048576) {
$bytes = round($bytes / 1048576 * 100) / 100 . &#39;MB&#39;;
} elseif($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . &#39;KB&#39;;
} else {
$bytes = $bytes . &#39;Bytes&#39;;
}
return $bytes;
}
?>