Home  >  Article  >  Backend Development  >  js php xmlrequest upload pictures_PHP tutorial

js php xmlrequest upload pictures_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:17714browse

I originally wanted to use a plug-in to upload images, but later I wrote a simple js to implement asynchronous image upload. Needless to say, the code is very simple

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 upload file




.txt{ height:28px; border:1px solid #cdcdcd; width:670px;}
.mybtn{ background-color:#FFF; line-height:14px;vertical-align:middle;border:1px solid #CDCDCD;height:30px; width:70px;} .file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }







Pictures


Browse...

Upload





http://www.bkjia.com/PHPjc/777991.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/777991.htmlTechArticle
I originally wanted to use a plug-in to upload pictures, but then I wrote a simple js to implement asynchronous picture upload, not much The code is very simple upload.php if(isset($_FILES["myfile"])) { $ret =...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn