Image upload is a necessary function of many websites, how to upload local images to the server? Look at the following
The browser gets the path to the uploaded file
type="file" name="attachment" id="attachment" />
Can only get the file name, but can not get the local path of the files, in fact, the browser to obtain the local path to upload the file is not secure, and now many browsers do not support this feature, in fact, this feature is only to display a thumbnail before uploading.
Upload file contents directly
Client-side code, here take the upload image as an example, on the server display uploaded pictures
Upload.html
<html> <!--upload.html -- <head> <title>Upload image file</title> </head> <body> <form Method="POST" action="upload.php" enctype ="Multipart/form-data"> <table Border=0 cellspacing=0 cellpadding=0 Align=Center Width="100%"> <tr> <TD Width= height= Align=" Center "> <input type="hidden" name="max_file_size" value= "2000000">FileName</td> <TD Height="+"> <input name="file " type="file"value= "View" /> <input type="Submit" value="Upload" name=" Attachment " /> </td> </tr> </table> </form> </body></html>
Server-side code, due to the PHP environment on the SAE, does not allow the server to save the uploaded files, where the servers code is directly display an uploaded temporary image
upload.php
<?php// upload.phpecho " . base64_encode( file_get_contents($_FILES[‘file‘][‘tmp_name‘]) ) . "‘ />"; ?>
PHP Base64_encode
PHP get_file_content
PHP $_files
PHP Learning Diary-Uploading files