Simple PHP for web files_PHP tutorial
php
web
share
Order
exist
implement
document
generate
of
Table of contents
Simple
Obtain
Very simple, used for file sharing on the web
1 Execute *nix command to obtain the files in this directory
2 Generate download link
3 Supports Chinese names, and the name can contain spaces
4 Please save the source code as utf-8 encoding
5 Assume that the sharing path is http://xx_host/xx_dir, the code is named index.php and placed in the xx_dir directory, and all file download links except index.php are generated
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>private file box</title> </head> <body> <h2>private file box</h2> <?php function list_file_url() { exec ( "tyncar.com/bin/ls", $res, $rc ); //echo "<pre class="brush:php;toolbar:false">"; // var_dump ( $res ); // var_dump ( $rc ); // echo ""; if (0 == $rc) { //echo count ( $res ) . "
"; //echo "
"; for($i = 0; $i < count ( $res ); $i ++) { if ($res[$i] != "index.php") { //echo $res [$i] . "
"; $encoded_url = urlencode($res[$i]); $encoded_url = str_replace("+","%20",$encoded_url); $encoded_filename = iconv("GBK","UTF-8",$res[$i]); $encoded_temp_filename = explode(".",$encoded_filename); $encoded_filename = $encoded_temp_filename[0]; echo "$encoded_filename"; echo "
"; echo "
"; } } } } list_file_url (); ?>