johnseito Posted February 10, 2008 Share Posted February 10, 2008 Hello everyone, I have a question with upload files. I create a html form and php codes to upload files. I also created a directory called uploads where my php upload files resides. when I upload it, all the files goes to the uploads directory. so my question is when I upload can it be save into mysql and then I can bring it out and show it in the browser instead of how i have it in the directory. How would I do this? I really want to show what I upload in the browser/server. thanks - Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 10, 2008 Share Posted February 10, 2008 A Blob field in mysql can store up to 4gb of data in binary. You just have to recreate the file from its binary using the headers in the browser Capable of doing any file type so long as you know the headers needed to recreate Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 10, 2008 Author Share Posted February 10, 2008 Thanks.. so far I have no clue what this field is. Can you show me a link that would give me more information on this? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 10, 2008 Share Posted February 10, 2008 http://dev.mysql.com/doc/refman/5.0/en/blob.html Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 10, 2008 Share Posted February 10, 2008 Here is a step-by-step tutorial on how to do it: http://www.php-mysql-tutorial.com/php-mysql-upload.php Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 10, 2008 Author Share Posted February 10, 2008 cooldude832 A Blob field in mysql can store up to 4gb of data in binary. thanks for the site Ok if it can store up to 4gb, how can i make it store more if in the end I want to? and I read the site provided by rhodesa, it said blob only stores Since BLOB is limited to store up to 64 kilobytes of data. rhodesa thanks for the site, I will read more about it. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 10, 2008 Share Posted February 10, 2008 Blobs have different types that range in max size, the largeblob or what ever its called is around 4gb I think Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 13, 2008 Author Share Posted February 13, 2008 I want to show the files in the browser, the image of it. I created one and it works but it doesn't work for all pictures, it doesn't show all pictures only some. Do you know why that is? I also would like to upload music and ms doc (mostly excel) files, so how would I select these and view them on the browser? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 An abridged method 1) The file is stored in temp, verify it didn't error on upload with the $_FILES['Input_name']['Error'] is empty 2) use the move_Uploaded_file to temporary transport it so you can then get its content use a random name just in case 3) Transfer the now temp file to mysql via file_get_contents, remember to store the file type headers and the extension 4) To recover just insert that content into a new file from a mysql query via echoing the output into the proper header document. Example would be upload.html <h1>Hello World!</h1> It was uploaded via a form $temp_folder = "temp/"; $num = rand(0,9999); move_uploaded_file("UPLOADED NAME", $temp_folder.$num."_".$_FILES['UPLAODED_NAME']['tmp_name']); #now insert $q = "Insert into `files` (FileName,Type,Content) VALUES('".$_FILES['UPLAODED_NAME']."", '".$extension."", ''.file_get_contents($temp_folder.$num."_".$_FILES['UPLAODED_NAME']['tmp_name'])."')"; ?> Now to recall it you just put it in a doc Very crude but general idea Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 14, 2008 Author Share Posted February 14, 2008 Hi I just noticed why some picture can't be uploaded, because some of those pictures files size are too large, about 600kb or 1.2 mb. I currently can only upload about 17 kb, how can I increase this capacity so that I can upload all my pictures? thanks Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 14, 2008 Share Posted February 14, 2008 alter the php.ini file and .htaccess (Depending on which one is limiting you) dont' know the exact syntax try google Quote Link to comment Share on other sites More sharing options...
johnseito Posted February 16, 2008 Author Share Posted February 16, 2008 Ok I got that, now a couple of things if you could offer some advice on. 1- I have the codes to upload pix and show them in the browser, but in only does it for one pix at a time and the last one uploaded. I would like to show all the pixs in the database with the last one uploaded showed last, I tried for the past two days to do this but haven't found any solution. if you have any let me know. 2 - do you know if or the codes to upload music and excel files to the database and show them on the browser? I was thinking that maybe I should do it as I did it for pix and change it to xls for excel docs, etc. thanks Quote Link to comment 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.