PHP Learning Diary-Uploading files

Source: Internet
Author: User

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

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.