Using jquery. form. js to upload images _ jquery

Source: Internet
Author: User
This article mainly introduces how to use jquery. form. js implements the Image Upload method, involving jquery using the form plug-in jquery. form. it is very simple and practical to use JavaScript to submit, verify the type, and display the execution result callback. If you need it, you can refer to the following example to describe how to use jquery. form. js implements the Image Upload method. We will share this with you for your reference. The details are as follows:

Testupfile2.php

<? Phpheader ('content-type: text/html; charset = UTF-8 '); include_once 'includes/common. inc. php'; if (! Empty ($ _ FILES ['upfile']) {// file format $ image = array ('image/jpg ', 'image/jpeg', 'image/png ', 'image/pjpeg ', 'image/gif', 'image/bmp', 'image/x-png '); $ updir = $ _ SERVER ['document _ root']. $ _ config ['G'] ['baseurl']. '/attached/images/'; $ upfile = $ _ FILES ['upfile']; $ name = $ upfile ['name']; $ ext = substr ($ upfile ['name'], strpos ($ upfile ['name'], '. '); $ upname = md5 (time (). rand (1, 1000 )). $ ext; $ type = $ upfile ['type']; $ size = $ upfile ['SIZE']; $ tmp_name = $ upfile ['tmp _ name']; $ error = $ upfile ['error']; $ OK = 0; foreach ($ image as $ key => $ value) {if ($ type = $ value) $ OK = 1;} if ($ OK = '1' & $ error = '0') {move_uploaded_file ($ tmp_name, $ updir. $ upname); // echo'
'. $ Tmp_name .'
'. $ Upname .'
'. $ Updir .'
'. $ Ext. 'uploaded successfully'; // echo 'uploaded successfully'; echo $ upname; // $ im = $ updir. $ upname; // echo $ im; // echo ''; // $ views-> assign ('image', $ upname ); // $ views-> display ('default/testupfile.html ');} else echo 'upload failed 2';} else echo 'upload failed 1';?>

Testupfile.html

 Insert title here

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.