file upload into mysql ( 7 Views )
-
I'm attempting to use the sample code from chapter 11 of Kevin Yank's book -- Database Driven Website. Everything <i>appears</i> to work. However, whenever I check the size of the temporary file created by php, it's size is 0. Therefore, none of the file actually gets put into mysql. Here is the code:
$uploadfile = $_FILES['uploadfile']['tmp_name'];
$uploadname = $_FILES['uploadfile']['name'];
$uploadtype = $_FILES['uploadfile']['type'];
$uploaddesc = $_POST['desc'];
// open file for binary reading ('rb')
$tempfile = fopen($uploadfile, 'rb');
// read the entire file into memory using PHP's
// filesize function to get the file size
$filedata = fread($tempfile, filesize($uploadfile));
// prepare for database insert by adding backslashes
// before special characters
$filedata = addslashes($filedata);
// create the SQL query
$sql = "INSERT INTO textandimages SET
file_name = '$uploadname',
mime_type = '$uploadtype',
description = '$uploaddesc',
file_data = '$filedata'";
// perform the insert
$ok = @mysql_query($sql);
Any help would be appreciated. Thank you.
(kerem ozan, Japan)
uploading binary data in mysql
Quote:
Originally Posted by anied52
I'm attempting to use the sample code from chapter 11 of Kevin Yank's book -- Database Driven Website. Everything <i>appears</i> to work. However, whenever I check the size of the temporary file created by php, it's size is 0. Therefore, none of the file actually gets put into mysql. Here is the code:
$uploadfile = $_FILES['uploadfile']['tmp_name'];
$uploadname = $_FILES['uploadfile']['name'];
$uploadtype = $_FILES['uploadfile']['type'];
$uploaddesc = $_POST['desc'];
// open file for binary reading ('rb')
$tempfile = fopen($uploadfile, 'rb');
// read the entire file into memory using PHP's
// filesize function to get the file size
$filedata = fread($tempfile, filesize($uploadfile));
// prepare for database insert by adding backslashes
// before special characters
$filedata = addslashes($filedata);
// create the SQL query
$sql = "INSERT INTO textandimages SET
file_name = '$uploadname',
mime_type = '$uploadtype',
description = '$uploaddesc',
file_data = '$filedata'";
// perform the insert
$ok = @mysql_query($sql);
Any help would be appreciated. Thank you.
|
Im not sure why you would want to upload binary data into your database, its slow and not a very efficient way to retrieve the data. You might want to email Kevin directly for some form of explanation.
good luck,
(Mehmet Can, Serbia and Montenegro)
Related Topics ... (or search in 1.720.883 topics !)
upload file for mysql (2) help with mysql and file upload (7) file upload problem in mysql (10) upload file to mysql database (2) file upload to mysql using oo php (10) file upload script to mysql. (9) upload large file into mysql db (6) upload a file and import into mysql table (8) php file upload to mysql blob (7)
copyright © 2007-2031 Pfodere.COM ( 5 Pfoyihuee Online )
|