Saving a file to my server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Saving a file to my server

Post by Anarking »

Hi there


I currently have this code that takes a file from a SQL database and lets you download. I want o create a zip file with many files in it so I need to save these files to a server.

How do I do this?


Currently I have this code

Code: Select all

 
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$query = "SELECT data,filename,filetype FROM uploads where id=$id";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"data");
$type = MYSQL_RESULT($result,0,"filetype");
$name = MYSQL_RESULT($result,0,"filename");
$names = str_replace(' ', '_', $name);
Header( "Content-type: $type");
Header("Content-Disposition: attachment; filename=$names");
print $data;
//echo $name;
?> 
 
Last edited by Benjamin on Sun May 03, 2009 4:50 pm, edited 1 time in total.
Reason: Changed code type from text to php, removed password.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Saving a file to my server

Post by it2051229 »

As long as you know how to read and use classes that's not a problem.. you can visit http://www.phpclasses.org and they provide ready made classes that you need. Regarding your problem, you can search in there the Class for Zipping or compressing files and folders which I have seen and been using for quite some time. There are a lot of versions of those and you just pick the one that suits you or you understand the most.
Post Reply