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