Copy to Clipboard引用的内容:[www.bkjia.com]
//显示上传状态和图片
//上传文件需要定义enctype,为了显示图片将target设为Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialframe enctype="multipart/form-data" target="Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialframe"> Upload a File:
//上传文件
上传图片函数 Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialimg:
Copy to Clipboard引用的内容:[www.bkjia.com]
function Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialimg(theform){ //提交Form theform.submit(); //在showimg
中显示上传状态 setStatus ("Loading...","showimg"); } //上传状态函数 function setStatus (theStatus, theObj){ obj = document.getElementById(theObj); if (obj){ obj.innerHTML = "
" + theStatus + "
"; } }
process_Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorial.php provides file Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorial function:
Copy to ClipboardQuoted content: [www.bkjia.com]
//Provide image type verification $allowedtypes = array("image/jpeg","image/pjpeg","image/png", "image/x-png","image /gif"); //File storage directory $savefolder = "images";
//Start working if there are files Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialed if (isset ($_FILES[' myfile'])){ //Check whether the Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialed file matches the $allowedtypes type if (in_array($_FILES['myfile']['type'],$allowedtypes)){ if ($ _FILES['myfile']['error'] == 0){ $thefile = "$savefolder/".$_FILES['myfile']['name']; //Upload files through move_Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialed_file if (!move_Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialed_file($_FILES['myfile']['tmp_name'], $thefile)){ echo "There was an error Ajax & PHP Learn and Practice Part 5 Image Processing_PHP Tutorialing the file."; } else{ ?> br />"http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd">
The doneloading function in the last part of the above code is used to display images and modify the image size. Thumb.php will be used, which will generate three sizes of large, medium and small source images in the images directory. If you are interested, you can study it. Welcome everyone to make bricks ~
Source code download: Sample6.rar
Reprinted from: http://www.cnblogs.com/gnielee/
http://www.bkjia.com/PHPjc/364410.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364410.htmlTechArticleIn the previous article, we explained how to submit the form through Ajax and have the underlying data processed by PHP. This article will mainly introduce it. Uploading and processing of images. Uploading files is very simple, just a Form...
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