ROCKINDANO Posted January 27, 2009 Share Posted January 27, 2009 Hello all, i have a question, will it be convenient to store pdf files on a db? if so can someone point me to a direction on how to? Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/ Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 in my person experience, i would not recommend storing the actual files in the DB. keep them in a folder, and have a record in your DB with info about the file Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747651 Share on other sites More sharing options...
ROCKINDANO Posted January 27, 2009 Author Share Posted January 27, 2009 right, acctually thats how i have it right now. but these are pdf's that are being listed weekly. so every time they put one in a folder i have to input a new record in a db. so i was thinking of having the files uploaded to db that way everytime that they do upload it produces a new link on the page with the current pdf. anyways, i guess ill keep it as i have it. but what would be one disadvantage of storing them in a db? Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747660 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 right, acctually thats how i have it right now. but these are pdf's that are being listed weekly. so every time they put one in a folder i have to input a new record in a db. so i was thinking of having the files uploaded to db that way everytime that they do upload it produces a new link on the page with the current pdf. anyways, i guess ill keep it as i have it. but what would be one disadvantage of storing them in a db? you can still have that...just have the upload move the PDF to the folder, and create a record in the database. the record would contain general info (filename, who uploaded it, when they uploaded it, etc) not the actual contents of the file i've just had lots of troubles with reading/writing the data, and performance problems when the files start getting big. i haven't done much with MySQLi though, which I think you can bind a field to a file handle for the INSERT. with the regular mysql functions you are supposed to base64 encode the data, then make a GIANT string for the INSERT query, then execute it Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747668 Share on other sites More sharing options...
ROCKINDANO Posted January 27, 2009 Author Share Posted January 27, 2009 thats right, i was thinking of uploading the acctual file into the db, but instead i could send it to a dir. and upload the db at the same time. hhhmmmm.. but how would i go about uploading the db at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747672 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 i assume by "uploading the db" you mean inserting a record... follow the PHP doc to get a script working that uploads a file and moves it to the folder first: http://us.php.net/manual/en/features.file-upload.post-method.php Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747685 Share on other sites More sharing options...
ROCKINDANO Posted January 27, 2009 Author Share Posted January 27, 2009 well this is what i have: uploadform.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>upload pdfs</title> </head> <body> <form action="uploadpdf.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="51200" /> <p>File to upload: <input type="file" name="fileupload" /></p> <p><input type="submit" value="upload!" /></p> </form> </body> </html> uploadpdf.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>uploading file</title> </head> <body> <?php $file_dir = "pdfs\\citysect\\"; foreach ($_FILES as $file_name => $file_array) { print "path: ".$file_array['"tmp_name"']. "<br />"; print "name: ".$file_array[''"name"]."<br />"; print "type: ".$file_array["'type'"]."<br />"; print "size: ".$file_array[''"size"]."<br />"; if (is_uploaded_file($file_array['"tmp_name"'])) { move_uploaded_file($file_array['"tmp_name"'], "$file_dir\".$file_array["name"]") or die ("could not moved"); print "file was moved!<br />"; } } ?> </body> </html> but its not uploading!!! can't see the error help! Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747689 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 try <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>uploading file</title> </head> <body> <?php $file_dir = "pdfs/citysect/"; $file= $_FILES['fileupload']; print "path: ".$file['tmp_name']. "<br />"; print "name: ".$file['name']."<br />"; print "type: ".$file['type']."<br />"; print "size: ".$file['size']."<br />"; print "error: ".$file['error']."<br />"; if (is_uploaded_file($file['tmp_name'])) { move_uploaded_file($file['tmp_name'],"$file_dir/".$file['name']) or die ("could not moved"); print "file was moved!<br />"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747708 Share on other sites More sharing options...
ROCKINDANO Posted January 27, 2009 Author Share Posted January 27, 2009 this is the output i am getting now path: name: PZpgchanges (2).pdf type: size: 0 error: 2 not uploading to dir path Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747711 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 yeah...that is why i added that error part. i noticed your MAX_FILE_SIZE seemed kind of small here is more info on the errors: http://us2.php.net/manual/en/features.file-upload.errors.php Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747713 Share on other sites More sharing options...
ROCKINDANO Posted January 27, 2009 Author Share Posted January 27, 2009 ah.... got it. Thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/142646-solved-storing-files-in-db/#findComment-747740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.