snakez Posted September 18, 2006 Share Posted September 18, 2006 Guys i need your help again pls... Just refer the code below and this is my explanation: Firstly the user can upload as many files as he want, then that uploaded files will be saved to the database after submit button was clicked. After that, a form will appear with the lists of the files uploaded(displayed in filenames only with links on each of them). If the user clicks to a particular filename, the file associated with that filename will be downloaded by the user. Ex. List of Files1. First.doc2. Second.txt3. three.jpeg4. four.gifNow, base on the example above, if i click the first.doc, the first.doc will be downloaded. but when i click others, still the first.doc will be downloaded. What should i do with my code below so that it will download the correct file that i clicked? By the way, the uploaded files was saved in an array.[code]<?php for($i=0;$i<count($_GET['id']);$i++){ $id=$_GET['id']; $filename=$_GET['filename']; $filetype=$_GET['filetype']; $filesize=$_GET['filesize']; $filecontent=$_GET['filecontent']; if (isset($id)) { include "include/opendb.php"; $query="SELECT $filename,$filetype,$filesize,$filecontent FROM fileuploads WHERE tracking='$id'"; $result=mysql_query($query) or Die("Error locating file for tracking Number: ".$id." ".mysql_error()); list($addfileName,$addfileType,$addfileSize,$addcontent)=mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$addfileName"); header("Content-length: $addfileSize"); header("Content-type: $addfileType"); echo $addcontent; exit; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21132-how-to-download-the-correct-linked-file/ Share on other sites More sharing options...
HuggieBear Posted September 18, 2006 Share Posted September 18, 2006 Morning snakez.The first thing you MUST confirm is that your database has the correct results in it. If you look at the tables in the database, are the links correct or are they all pointing to the first file?No point in checking the code on the page that pulls the info from the database if the database is incorrect (implying the code that inserts it is wrong).RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21132-how-to-download-the-correct-linked-file/#findComment-93865 Share on other sites More sharing options...
snakez Posted September 18, 2006 Author Share Posted September 18, 2006 I already checked the database and it works fine. The files are in correct situation in the table... By the way all of those files are having the same ID number("ex. 00001") and if a form will be viewed with an ID number for example "00001" then all of them will be displayed... And i already made them displayed in correct sequence using an array... perhaps the only problem here i think is how to linked them in a correct file or sequence... Quote Link to comment https://forums.phpfreaks.com/topic/21132-how-to-download-the-correct-linked-file/#findComment-94310 Share on other sites More sharing options...
HuggieBear Posted September 19, 2006 Share Posted September 19, 2006 Is the tracking field in the database unique? You have this line:[code=php:0]SELECT $filename,$filetype,$filesize,$filecontent FROM fileuploads WHERE tracking='$id'[/code]$id is coming from the variable $_GET['id'] and you're using WHERE with EQUALS instead of IN, so I was assuming there'd be only one id passed to the sql statement, but more than one row in the database with a 'tracking' value of $id.[color=red][size=8pt][b]EDIT:[/b][/size][/color] I've just had a thought. In you're loop, you're outputting a header and then you echo content, then you loop again. I'm not sure you can send headers more than once can you?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21132-how-to-download-the-correct-linked-file/#findComment-94491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.