Page 1 of 2

download file from database, upload to a file server

Posted: Mon Jul 02, 2007 3:23 pm
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

Posted: Mon Jul 02, 2007 3:35 pm
by volka
e.g. file_put_contents() works with some url wrappers like ftp

Posted: Mon Jul 02, 2007 4:34 pm
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

Posted: Mon Jul 02, 2007 5:54 pm
by vigge89
There's always the FTP functions.

Posted: Mon Jul 02, 2007 6:07 pm
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

Posted: Mon Jul 02, 2007 6:51 pm
by volka
How can you access this file server?

Posted: Mon Jul 02, 2007 6:53 pm
by nayeemmz
all the ssh2 functions
I am already using ssh2_scp_send for some other operations .

Posted: Mon Jul 02, 2007 6:58 pm
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

Posted: Mon Jul 02, 2007 7:01 pm
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?

Posted: Mon Jul 02, 2007 7:04 pm
by volka
If you can use the ss2 url wrapper maybe yes.

Posted: Mon Jul 02, 2007 7:06 pm
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.

Posted: Mon Jul 02, 2007 7:11 pm
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.

Posted: Mon Jul 02, 2007 7:11 pm
by volka

Posted: Mon Jul 02, 2007 7:17 pm
by nayeemmz
Volka and tecktalkcm0391,

Thanks.

I will look into these examples and see if I can make it work.

Posted: Mon Jul 02, 2007 7:24 pm
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.