homepage Welcome to WebmasterWorld Guest from 54.234.59.94
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Force Download and File Rename
Shanee




msg:3333660
 12:12 pm on May 8, 2007 (gmt 0)

hello to all
i have the php function for force download which also update the total number of downloads to MYSQL DB, the problem is i want to rename the orignal file name to new name, for example orignal name is file.mp3 (on the server) must be change to file-blah-blah.mp3 (when user want to download). here is my function below. i will realy love if someone solved my problem

$sql = "select * from table where tableID = $tableId";

$result = mysql_query($sql ,$db);

if ($myrow = mysql_fetch_array($result)) {

do {

$downloads = $myrow["downloads"] + 1;

} while ($myrow = mysql_fetch_array($result));

}

$sql = "update wallpaper set downloads = $downloads where tableID = $tableID";

$result = mysql_query($sql ,$db);

$newurl = "images/" . $size . "/" . $wallpaperid . ".jpg";

Header("Location: $newurl");

 

Scally_Ally




msg:3333722
 1:19 pm on May 8, 2007 (gmt 0)

Instead of actually redirecting to the actual file, you could just stream the file out using the appropriate headers.

Use fread() to read the file and write the binary content to the page. Use the appropiate headers to then force the download / display of this file.

something like
$myvar = contents of file chosen (fread())

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"file.csv\"");

echo $myvar;

you could then change the filename to whatever you wanted.

check this link out for mimes
[w3schools.com...]
and this for fread()
[uk2.php.net...]

Ally

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved