0

Hi!

I need help with bulk export of files from database to folder. I have upgraded a system that i made and now instead of storing files to database i store it in folder and save path to database. Now i have a problem because there are around 1500 parts with attached certificates in database. I need to extract them with a script to folder on the server with name rowid.pdf so i know latter which certificate goes where. I have this for now:

$basedir = 'C:\wamp\www\...\\';
$host = 'localhost';
$user = '***'; 
$password= '***'; 
$dbname = '***';

$type = 'pdf';
$blob_id = 'system_batch_number';
$blob_data = 'certificate';
$blob_table = 'parts';

// ************************************************** ***************

$db = mysql_connect($host, $user, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($dbname, $db);

$sql = "SELECT $blob_id, $blob_data FROM $blob_table";
echo $sql;
$result_files = mysql_unbuffered_query($sql);

header('Content-Type: application/pdf');

while ($row = mysql_fetch_array($result_files, MYSQL_ASSOC)) {
$id = $row["$blob_id"];
$data = $row["$blob_data"];
$file = "$basedir$id.$type";
echo "Looking for File: $file<br>";
if (!file_exists($file)) {
$fp=fopen($file,"wb");
echo "Opening File: $file<br>";
fwrite($fp,$data1);
echo "Writing File: $file<br>";
fclose($fp);
echo "Closeing File: $file<br>";
} else {
echo "Skipping File: $file<br>";
}
sleep(1);
}

mysql_free_result($result);

It exports everythng like i need only all files are empty and unsopported when i try to open them...

Thank you!

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by dbalas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.