download file from database, upload to a file 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

nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

download file from database, upload to a file server

Post by nayeemmz »

Hi,

I have some files stored in the database as longblob, with the filenames as well.

I want to download these files from the database and save them on a remote file server.

I do not want to download the files using a url which is a common practice, rather the download from the mySQL database and upload to the file server should happen without the user's intervention. I need to run some tests on the file , on the remote server. These files need to be in the database because other users need to use them as well.


Is there a way to do this?

I would appreciate any help.

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g. file_put_contents() works with some url wrappers like ftp
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Hi volka,

Thanks for your response.

However, file_put_contents() works only for php 5 and above.
In my setup it complains about call to an undefined function.

Is there any other function like this?

Thanks
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

There's always the FTP functions.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Viggie89,

Thanks.

the ftp functions are not allowed in our set up .
However, that is a secondary problem, because even if ftp worked , it would need a source file.

I don't have any. I want to read from the database and write to a remote file without creating any local files.

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

How can you access this file server?
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

all the ssh2 functions
I am already using ssh2_scp_send for some other operations .
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But the ssh2 extension does not provide a function to send something else than a file.
Maybe you can use http://de2.php.net/manual/en/wrappers.ssh2.php
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

you are right and that is the reason I am kind of stuck.

Can fopen and fwrite be used in some way to write to a remote file?

Can I stream the database output to the file server, somehow?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you can use the ss2 url wrapper maybe yes.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Thank you.

But I have no idea how to do that.

Is there any example you could share with me?

I appreciate your help.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Code: Select all

header("Content-type: text/richtext"); // what ever the content is 
header('Content-Disposition: attachment; filename="'.$filename.'"'); // send as download and filename as 
echo $the_file;  // echo file data
Don't know if that would work.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post by nayeemmz »

Volka and tecktalkcm0391,

Thanks.

I will look into these examples and see if I can make it work.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

tecktalkcm0391 wrote:

Code: Select all

header("Content-type: text/richtext"); // what ever the content is 
header('Content-Disposition: attachment; filename="'.$filename.'"'); // send as download and filename as 
echo $the_file;  // echo file data
Don't know if that would work.
this will send the data to the client/browser, not another file server.
Post Reply