当前位置:Gxlcms > PHP教程 > php+js实现异步图片上传实例分享_PHP

php+js实现异步图片上传实例分享_PHP

时间:2021-07-01 10:21:17 帮助过:23人阅读

upload.php

代码如下:
if(isset($_FILES["myfile"]))
{
$ret = array();
$uploadDir = 'images'.DIRECTORY_SEPARATOR.date("Ymd").DIRECTORY_SEPARATOR;
$dir = dirname(__FILE__).DIRECTORY_SEPARATOR.$uploadDir;
file_exists($dir) || (mkdir($dir,0777,true) && chmod($dir,0777));
if(!is_array($_FILES["myfile"]["name"])) //single file
{
$fileName = time().uniqid().'.'.pathinfo($_FILES["myfile"]["name"])['extension'];
move_uploaded_file($_FILES["myfile"]["tmp_name"],$dir.$fileName);
$ret['file'] = DIRECTORY_SEPARATOR.$uploadDir.$fileName;
}
echo json_encode($ret);
}

?>

index.html

代码如下:



Html5 Ajax 上传文件









浏览...

上传


人气教程排行