TGWSE_GY Posted April 26, 2009 Share Posted April 26, 2009 Hi guys, I have my table setup in mysql for storing the base64_encode() string for images. I am wanting to allow the user to upload 5 images at a time, however I know I am going to need to test to make sure of which fields return a actual value to script before storing the base64 results in the table. I am wondering what would be the best method for testing for "NULL" value passed to the script because of an empty field and omitting that item obviously because it is NULL. Any help would be very helpful. Thanks Link to comment https://forums.phpfreaks.com/topic/155752-solved-letting-users-upload-multiple-images-testing-for-null-fields/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2009 Share Posted April 26, 2009 A) Don't use base64_encode() to store binary information anywhere, because that will increase the storage requirements by 33% more space than the original data. base64_encode() is intended when you must transmit binary data through a method that does not support binary transfer. B) Add the following debugging code so that you can see what you do get when a file upload field is left blank - echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; Link to comment https://forums.phpfreaks.com/topic/155752-solved-letting-users-upload-multiple-images-testing-for-null-fields/#findComment-819858 Share on other sites More sharing options...
TGWSE_GY Posted April 26, 2009 Author Share Posted April 26, 2009 here is the code that I run session_start(); if (isset($_SESSION['Usr'])) { // Grab Images from image_upload.php form $Image1 = $_FILES['formImage1']; $Image2 = $_FILES['formImage2']; $Image3 = $_FILES['formImage3']; $Image4 = $_FILES['formImage4']; $Image5 = $_FILES['formImage5']; echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; die(); and this is the response I get, I uploaded 4 files and left the 5th null. FILES:Array ( [formImage1] => Array ( [name] => 3293041108_5133a1c0fa.jpg [type] => [tmp_name] => [error] => 2 [size] => 0 ) [formImage2] => Array ( [name] => head.jpg [type] => image/jpeg [tmp_name] => /tmp/php5Oq6gT [error] => 0 [size] => 7583 ) [formImage3] => Array ( [name] => little-men3.png [type] => image/png [tmp_name] => /tmp/phpuxye6W [error] => 0 [size] => 6293 ) [formImage4] => Array ( [name] => header_green_geo.png [type] => image/png [tmp_name] => /tmp/phpIf1vrZ [error] => 0 [size] => 8712 ) [formImage5] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) Link to comment https://forums.phpfreaks.com/topic/155752-solved-letting-users-upload-multiple-images-testing-for-null-fields/#findComment-819883 Share on other sites More sharing options...
TGWSE_GY Posted April 26, 2009 Author Share Posted April 26, 2009 So do I test the size value for greater than 0 and if its true insert it into the database? and also if its not a good idea to use base64_encode because of space requirements to store the images in the MYSQL DB, then how do I store them into a MYSQL table. Thanks Link to comment https://forums.phpfreaks.com/topic/155752-solved-letting-users-upload-multiple-images-testing-for-null-fields/#findComment-819888 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2009 Share Posted April 27, 2009 Only the 2nd, and 3rd files actually uploaded. The 1st and 4th have errors - http://www.php.net/manual/en/features.file-upload.errors.php You must test the ['error'] element before you attempt to use any of the uploaded file information. You should also use an array for the field name so that you can simply loop to process all the files instead of repeating code for each file - http://www.php.net/manual/en/features.file-upload.multiple.php Databases are not file storage engines. Operating system file systems are. There is additional overhead and several limitations when storing and retrieving files in a database. Store files in an operating system file system, that is what it was designed to be efficient at doing. If you must store binary data in a database, use a BLOB data type. Link to comment https://forums.phpfreaks.com/topic/155752-solved-letting-users-upload-multiple-images-testing-for-null-fields/#findComment-820010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.