Forum Moderators: coopster

Message Too Old, No Replies

upload and download a file from sql table using php

         

bablu

6:19 pm on Mar 12, 2011 (gmt 0)

10+ Year Member



we want 2 upload file into database and also download it from mysql database using php..please help us..

rocknbil

3:46 pm on Mar 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



look into mysqldump, to create the backup:

$command = "mysqldump -h $dbhost --user=$dblogin --password=$dbpass $dbname > $yourdirectory/$file";
$result = system($command);

.... will give a backup file with filename $file, be sure $yourdirectory is writable by PHP. Also be sure to read the result if it doesn't work:

if ($result) { die("could not make backup: $result"); }

To download it you open it and generate download headers, then just do readfile($file) (be sure to use full system path, NOT URL.)

Then to upload, you build a standard upload routine that ends with something like

$command = "mysql --user=$dblogin --password=$dbpass $dbname < $yourdirectory/$file";
$result = system($command);

where $file is a cleansed version of the uploaded filename. Note > and <, they should be familiar. :-)