Can a mysql database be updated only once? In addition, how can we compare the results with strings for php's download function? the completed functions include:
1. if you have not logged on, go to the logon page.
2. download count
The code is as follows: (I have three questions in the code comments. thank you very much)
Click the file to be downloaded (a link) to go to the singledownload. php page to process the download.
& File_name = & File_id = '/>
Code for the singledownload. php page
$ File_name = $ _ GET ['File _ name']; // file name (found in the database) $ file_dir = $ _ GET ['File _ dir']; // file path (fixed) $ file_id =$ _ GET ['File _ id']; // file id (found in the database) /* connect to the database */$ link = mysql_connect ("localhost", "root", "root"); mysql_select_db ("wpgc", $ link ); $ q = "SELECT * FROM downloads WHERE file_id = ". $ file_id; mysql_query ("set names UTF-8"); $ rs = mysql_query ($ q, $ link); // get the result SET if (! $ Rs) {die ("invalid result set");} // permission detection if (! Is_user_logged_in () {// if you have not logged on to if ($ row [10] = "2 ") {// Check File permission '2' indicates that this file can be downloaded only after logon. // Question 1: $ row [] What is it? I have not defined it anywhere, and the program has not entered here; but $ row [1] in the link is successful, I want $ row [] to be the value stored in the database echo "script window. location = '.. /.. /.. /login. php'; script ";}}/* calculate the number of downloads */$ downloadcount = $ row [9]; $ downloadcount = $ downloadcount + 1; $ SQL = "UPDATE downloads SET file_hits = ". $ downloadcount. "WHERE file_id = ". $ file_id; // Question 2: The update can only be performed once. the first time you download and update the file_hits field from 0 to 1, the download will not change if (mysql_query ($ SQL, $ link )) {} else {} // Question 3: This if statement always says no text can be found File, but after this annotation, the download of the file is normal if (! File_exists ($ file_dir. $ file_name) {echo "[" not found [". $ file_dir. $ file_name. "] file"; exit;} else {/* starts to download the file (this is normal) */$ file = fopen ($ file_dir. $ file_name, "r"); Header ("Content-type: application/octet-stream"); Header ("Accept-Ranges: bytes "); header ("Accept-Length :". filesize ($ file_dir. $ file_name); Header ("Content-Disposition: attachment; filename = ". $ file_dir. $ file_name); echo fread ($ file, filesize ($ file_dir. $ f Ile_name); $ buffer = 1024; while (! Feof ($ file) {$ file_data = fread ($ file, $ buffer); echo $ file_data;} fclose ($ file );
I am a beginner in php. please advise more...
Reply to discussion (solution)
1. isn't it the code you wrote? you don't know others, but you don't know others.
2. print out the pairs of different values
3. the path is incorrect.
1. isn't it the code you wrote? you don't know others, but you don't know others.
2. print out the pairs of different values
3. the path is incorrect.
I did what others wrote, so I have a lot of questions ..
Imitation is useless.
You need to know what you want to do