Php + js implements asynchronous image Upload instance sharing. The upload. php copy code is as follows :? Phpif (isset ($ _ FILES [myfile]) {$ retarray (); $ uploadDirimages. DIRECTORY_SEPARATOR.date (Ymd). DIRECTORY_SEPARATOR; $ dirdirname (upload. php
The code is as follows:
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
The code is as follows:
Upload files using Html5 Ajax