ma5ect Posted July 1, 2008 Share Posted July 1, 2008 I have a download script which holds files which have been uploaded by the users.. the files are shown on this page but once i try to open them, nothin happens...any1 help script <?php require_once('Connections/mysql_connect.php'); ?> <?php if(isset($_GET['name'])) { $name = $_GET['name']; $query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); echo $content; exit; } mysql_select_db($database_mysql_connect, $mysql_connect); $query_Recordset1 = "SELECT * FROM uploadfiles"; $Recordset1 = mysql_query($query_Recordset1, $mysql_connect) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); mysql_free_result($Recordset1); ?> <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? $query = "SELECT name FROM uploadfiles"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($name) = mysql_fetch_array($result)) { ?> <a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br> <? } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/ Share on other sites More sharing options...
Tchelo Posted July 1, 2008 Share Posted July 1, 2008 You are passing id as $_GET['id'], but you are checking for $_GET['name']. Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579071 Share on other sites More sharing options...
ma5ect Posted July 1, 2008 Author Share Posted July 1, 2008 am sorry i cannot see this... Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579075 Share on other sites More sharing options...
Tchelo Posted July 1, 2008 Share Posted July 1, 2008 Although this is not the best method, try changing the following line <a href="download.php?id=<?=$id;?>"><?=$name;?> to <a href="download.php?name=<?=$name;?>"><?=$name;?> This should do the trick. Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579077 Share on other sites More sharing options...
ma5ect Posted July 1, 2008 Author Share Posted July 1, 2008 now the files are displayed all in a line and are not recognised file types.. when i click open the following error appears: Warning: Header may not contain more than a single header, new line detected. in C:\xampp\htdocs\download.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\download.php:12) in C:\xampp\htdocs\download.php on line 13 Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579085 Share on other sites More sharing options...
Tchelo Posted July 1, 2008 Share Posted July 1, 2008 Not sure if this will fix it, but check what you are doing with list($name, $type, $size, $content) = mysql_fetch_array($result); You are trying to set $name first, but you did not select name on your sql statement. Just remove $name from the list() parameters. Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579092 Share on other sites More sharing options...
ma5ect Posted July 1, 2008 Author Share Posted July 1, 2008 i have got it to open the files thanx...but 1 problem, the files are all shown in a single line instead of a column... Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579097 Share on other sites More sharing options...
Tchelo Posted July 1, 2008 Share Posted July 1, 2008 Add <br/> after the link, like so: <a href="download.php?name=<?=$name;?>"><?=$name;?><br/> Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579104 Share on other sites More sharing options...
ma5ect Posted July 1, 2008 Author Share Posted July 1, 2008 great thanx....will this script allow me to open any files that the user uploads.. Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579114 Share on other sites More sharing options...
Tchelo Posted July 1, 2008 Share Posted July 1, 2008 I believe it will. If your problem is solved, hit the solved button. =D Link to comment https://forums.phpfreaks.com/topic/112751-solved-files-wont-open/#findComment-579125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.