Use jquery. form. js to upload images. Use jquery. form. js to upload images.
This document describes how to upload images using jquery. form. js. 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 '<br> '. $ tmp_name. '<br> '. $ upname. '<br> '. $ updir. '<br> '. $ 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
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">