5 Image Processing for learning and practicing Ajax + PHP

Source: Internet
Author: User

First:


Create a form in sample6_1.php:

CopyCode The Code is as follows: // display the upload status and Image
<Div id = "showimg"> </div>
// Enctype needs to be defined for file uploading. set target to uploadframe for image display.
<Form ID = "uploadform" Action = "process_upload.php" method = "Post"
Enctype = "multipart/form-Data" target = "uploadframe">
Upload a file: <br/>
<Input type = "file" id = "myfile" name = "myfile"/>
// Upload a file
<Input type = "Submit" value = "Submit" onclick = "uploadimg (document. getelementbyid ('uploadform'); Return false;"/>
<IFRAME id = "uploadframe" name = "uploadframe" src = "process_upload.php" class = "noshow"> </iframe>
</Form>

Upload image function uploadimg:Copy codeThe Code is as follows: function uploadimg (theform ){
// Submit the form
Theform. Submit ();
// Display the upload status in showimg <div>
Setstatus ("loading...", "showimg ");
}
// Upload status Function
Function setstatus (thestatus, theobj ){
OBJ = Document. getelementbyid (theobj );
If (OBJ ){
OBJ. innerhtml = "<Div class = \" bold \ ">" + thestatus + "</div> ";
}
}

Process_upload.php provides the file upload function:Copy codeThe Code is as follows: <? PHP
// Provides image type verification
$ Allowedtypes = array ("image/JPEG", "image/pjpeg", "image/PNG", "image/X-PNG", "image/GIF ");
// File storage directory
$ Savefolder = "Images ";

// start to work if a file is uploaded
If (isset ($ _ FILES ['myfile']) {
// check whether the uploaded file meets the $ allowedtypes type
If (in_array ($ _ FILES ['myfile'] ['type'], $ allowedtypes )) {
if ($ _ FILES ['myfile'] ['error'] = 0) {
$ thefile = "$ savefolder /". $ _ FILES ['myfile'] ['name'];
// upload a file using move_uploaded_file
If (! Move_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name'], $ thefile) {
echo "There was an error uploading the file. ";
}< br> else {
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">






" OnLoad=" doneloading (parent, ' ') ">


}< BR >?>

the doneloading function in the last part of the code above is used to display the image and modify the image size. Thumb. php will be used, and the size of the source image will be generated in the images directory. If you are interested, you can study it. You are welcome to make a brick ~
package and download the source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.