Php programming for file download statistics

Source: Internet
Author: User
Many download files on websites now provide statistical functions. This article describes how to use php to implement this function. programmers who want to hide the download file path and avoid using the url to download files directly, this article also has some reference value. Implementation environment: Linux + Apache + Php + MysqlWindows98 + PWS4 + Php + MySyntaxHigh

Many download files on websites now provide statistical functions. This article describes how to use php to implement this function. programmers who want to hide the download file path and avoid using the url to download files directly, this article also has some reference value. Implementation environment: Linux + Apache + Php + MysqlWindows98 + PWS4 + Php + Mysql I. create a table in the database structure database to store file information, including file encoding, name, download path, and statistics. the corresponding SQL file content is as follows: CREATE DATABASE dl_db; CREATE TABLE dl_file (id varchar (6), name varchar (50 ), url varchar (200), count bigint (10); insert into dl_file VALUES (000001, test, test.zip, 0); insert into dl_file VALUES (000002, tif, download/123.tif, 0); 2. php Programming 1. function files include database connection initialization functions and prompt information display functions. Dl_func.php3: 2. download connection page read the downloaded file information from the database and display it. Filelist. php3:File Download "; Echo" $ arr_dlfile [name] "; echo" "; echo" (downloads: $ arr_dlfile [count]) "; echo"


";} Mysql_close ($ dl_in);?>3. when a file exists on the download page, go to the file to be downloaded. If an error occurs, a prompt is displayed. Filedown. php3: The principle is that filelist. php3 displays the connections of all files, obtains the name and path of the file based on the passed id, and downloads the file through location. The above procedures have been tested and run properly. The file url can be local or on another server. If the file content is stored in the database, or the file is not in the http or ftp path, you can echo the file content to replace the header ("location: $ arrfile [url] "), because the method for reading files is relatively simple, we will not repeat it here.

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.