Re: file downloads

From: Date: Wed, 08 Aug 2001 01:31:04 +0000
Subject: Re: file downloads
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-61946@lists.php.net to get a copy of this message
View your Apache logs after doing these mods, just in case the database has died after your testing that worked: It's also good to have these lines stay in there so you can debug later... > <?php > mysql_connect("localhost","user","pass"); ... or error_log(0, "Could not connect to database in " . __FILE__ . ":" . __LINE__); > mysql_select_db("db"); ... or error_log(0, "Could not select db in " . __FILE__ . ":" . __LINE__); > $query = "SELECT file_path from photos where photos_id=$photos_id"; > $result = @mysql_query($query); ... or error_log(0, "Could not exec $query in " . __FILE__ . ":" . __LINE__); > $row = mysql_fetch_row($result); > $path = $row[0]; > $file_name = basename($path); > file://print "<img src=\"$path\">"; > file://print "<div align=\"center\">$file_name</div>"; > > header("Content-Type: application/download\n"); Why are you adding a \n there? That pretty much pukes the rest of the headers, since it's a newline you've forced in, and now the other stuff is part of the data, not the headers... Also, use application/octet-stream for download, I think. > header("Content-Disposition: attachment; filename=$file_name"); > header("Content-Transfer-Encoding: binary"); Is this the full path or a relative path? I never trust relative paths when it comes to file-system operations. But I have a low trust-value in computers, software, and life in general. :-) > readfile($path); > > ?> > > This should work shouldn't it? If you did it right, it would work. :-)

« previous php.general (#61946) next »