PHP implementation file upload and download with display files and directory features

Source: Internet
Author: User
Tags php file upload
This article mainly introduces the php file upload and download the accompanying display files and directory features, the need for friends can refer to the following

Main Page wenjianceshi.php

<! DOCTYPE html>

Show:

Upload Processing page upload.php

<?PHPIF ($_files["File" ["Error"]) {  echo $_files["file"] ["Error"];} else{  if ($_files["file"] ["size"]<10240000)  {    //prevents file names from repeating    $filename = "./a/". Time (). $_files[" File "[" name "];    transcoding    $filename = Iconv ("UTF-8", "gb2312", $filename);    if (file_exists ($filename))    {      echo "The file already exists";    }    else    {      //Save file      move_uploaded_file ($_files["file"] ["Tmp_name"], $filename);      Header ("location:wenjianchuanshu.php");    }  }  else  {    echo "file type not";  }}

Selecting a file after clicking the file will display:

Click Upload.

Download Processing page download.php

<?php$url = $_get["url"]; $bname = basename ($url); Header ("Content-type:text/html;charset=utf-8"); $file _name= "{$bname}"; To solve the problem that cannot be displayed in Chinese $file _name=iconv ("Utf-8", "gb2312", $file _name); $file _sub_path=$_server[' Document_root ']; $file _path= "{$url}"; The first thing to judge is whether the given file exists or not (!file_exists ($file _path)) {echo "does not have the file"; return;} $fp =fopen ($file _path, "R"); $file _size=filesize ($file _path); The header ("Content-type:application/octet-stream") to be used to download the file; Header ("Accept-ranges:bytes"); Header ("Accept-length:". $file _size); Header ("content-disposition:attachment; Filename= ". $file _name); $buffer = 10240000; $file _count=0; Return data to the browser while (!feof ($fp) && $file _count< $file _size) {$file _con=fread ($fp, $buffer); $file _count+=$ Buffer echo $file _con; } fclose ($FP);

Clicking on the download will pop up the download box and download it.

Click on the folder or the previous layer of processing page chuli2.php

<?phpsession_start (); $url = $_post["url"];$_session["fname"] = $url;

The above is the whole content of this article, I hope that everyone's study has helped.


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.