PHP file down, upload

Source: Internet
Author: User
Tags fread php file upload
php file Upload, download

In the past has been doing Java, the recent career to engage in PHP development, always feel powerless. These days there is a need for PHP file upload and download. To share their own learning materials.

?

1. First request page upload.html

  Administration-upload New files

Upload New News Files

?

2.php processing the data requested by the client upload.html

  <title>Uploading ...</title>

Uploading file ...

0) {echo ' problem: '; Switch ($_files[' userfile ' [' Error ']) {case 1:echo ' File exceeded upload_max_filesize '; Break Case 2:echo ' File exceeded max_file_size '; Break Case 3:echo ' File only partially uploaded '; Break Case 4:echo ' No file uploaded '; Break Case 6:echo ' cannot upload file:no temp directory specified. '; Break Case 7:echo ' Upload failed:cannot write to disk. '; Break } exit; }//Does The file has the right MIME type? if ($_files[' userfile ' [' type ']! = ' Text/plain ') {echo ' problem:file is not plain text '; Exit }//Put the file where we ' d like it $upfile = '/uploads/'. $_files[' userfile ' [' name ']; if (Is_uploaded_file ($_files[' userfile ' [' tmp_name '])) {if (!move_uploaded_file ' $_files[' [' UserFile '], $ Upfile) {echo ' problem:could not move file to destination directory '; Exit }} else {echo ' problem:possible file upload attack. Filename: '; Echo $_files[' UserFile ' [' name ']; Exit } Echo ' File uploaded successfully

'; Reformat the file contents $fp = fopen ($upfile, ' R '); $contents = Fread ($fp, FileSize ($upfile)); Fclose ($FP); $contents = Strip_tags ($contents); $fp = fopen ($upfile, ' w '); Fwrite ($fp, $contents); Fclose ($FP); Show what is uploaded echo ' Preview of uploaded file contents:
'; Echo $contents; Echo '
';? >

?

3.php File Download

 
  

In general, the above 3 code snippets simply introduced the php file upload download, there are many problems to solve, such as uploading large files when how to deal with, batch upload, large file download and so on. Of course, like Java, PHP also has a lot of frameworks to solve this.

  • 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.