Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Getting binary data from MySQL to download into a zip (https://novahq.net/forum/showthread.php?t=21239)

BeBop 12-12-2004 07:49 AM

Getting binary data from MySQL to download into a zip
 
Sorry bout the long name...

Well anyways, now since ive got hte whole displaying an imge thing working, how would i get it so pretty much the same works with a zip file so the person (upon clicking hte link) will get the zip file to download?

This is what i have so far and it just gives me a dl.php filled with the binary data lol...

PHP Code:

 $query "SELECT * FROM mapdb_maps WHERE mid='$id'";
    
$result mysql_query($query) or die(mysql_error());

    while(
$row mysql_fetch_array($result)){
    
$data $row['file'];
    
    }
    
    
header("Content-type: application/x-zip");
    echo 
$data


Scott 12-12-2004 10:03 PM

Try storing at least the origional file extension on the database.. Then use the octet-stream.

Try something like this:

$result=result("SELECT origional_name,extension FROM database WHERE map='$id'");

header("Content-Type: application/octet-stream");
header( "Content-Disposition: attachment; filename=$origional_name.$extension");
exit;

BeBop 12-13-2004 05:42 AM

ok it goes to a zip file now but doesnt have any data in it :-X

Scott 12-13-2004 12:38 PM

I'll look into it a bit more when I get home. I've never taken data outa a mysql db for file download.. I'll figure it out..

BeBop 12-13-2004 03:10 PM

Thanks panther :-D

right now with what you give me, i can get a zip file with the name from the datqabase, but not the data thats in it...

Scott 12-13-2004 05:17 PM

Code:

<?
$result=result("SELECT * FROM filename,blob FROM table WHERE id='$id'");

header("Content-Disposition: attachment; filename=\"$result[filename]\"");
// or try header("Content-Disposition: inline; filename=\"$result[filename]\"");
header("Content-Length: ".strlen($result[blob]));
header("Content-Type: application/octet-stream");

Echo($result[blob]);
?>


BeBop 12-13-2004 05:46 PM

you bloody rock Panther

i changed it just a lil so it would suit me

header("Content-Disposition: attachment;
// the $name and $data are already called form the database, just recalled the vars here
filename=\"$name\".zip");
// .zip for file type
header("Content-Length: ".strlen($data));
header("Content-Type: application/octet-stream");

Scott 12-13-2004 06:04 PM

1 Attachment(s)
I wrote a script for you in full if you run into a few more errors.. It has a few more explinations like how to do images etc.. Sorry for all the errors above, I wasen't testing anything I was writing.. But glad you got it to work! :). Nice to know someone is trying out there.

you'll have to change some things to test it out / play with it but it's a sample / play script for learning.

BeBop 12-13-2004 07:44 PM

ty i already got it working heheh

http://67.8.147.5/?pg=Map%20Database&cat=1

Scott 12-13-2004 07:47 PM

gj bro :)


All times are GMT -5. The time now is 07:37 PM.

Powered by vBulletin®