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.