search
Homephp教程php手册js php xmlrequest 上传图片的方法

js php xmlrequest 上传图片的方法

Jun 13, 2016 am 09:33 AM
phpuploadpictureaccomplishplug-inmethodofSimpleOwn

   本来想用插件上传图片的,后来自己写了一个简单的js实现异步的图片上传,不多说上代码非常简单

  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

  





浏览...

上传


 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools