Re: file downloads

From: Date: Sat, 04 Aug 2001 15:57:11 +0000
Subject: Re: file downloads
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61245@lists.php.net to get a copy of this message
> Why does this code produce a page cannot be displayed error? Your query is probably wrong. Comment out the header stuff and add some error checking to your query. > <?php > mysql_connect("localhost","username","password"); > mysql_select_db("database"); > $query = "SELECT file_path from photos where photos_id=$photos_id"; > $result = @mysql_query("$query"); The quotes are useless there. Change the above to: $result = mysql_query($query) or die(mysql_error()); > $row = mysql_fetch_row($result); > $path = $row[0]; > $parts = split("/",$path); Use explode() instead. No sense wasting a regex on a trivial delimiter like that. > $file_name = $parts[count($parts)-1]; uh.. basename() would do the same thing, so you can get rid of this line and also the split/explode actually. > header("Content-Type: application/download\n"); > header("Content-Disposition: attachment; filename=$file_name"); > header("Content-Transfer-Encoding: binary"); > $fn=fopen($path , "r"); > fpassthru($fn); readfile($path); would replace those two lines. -Rasmus

« previous php.general (#61245) next »