vmicchia Posted February 16, 2011 Share Posted February 16, 2011 I am working on a file upload that stores the image in the database. my upload field is this: <input type="file" name="image1[]" /> and my php to process the file and upload it is this: $maxsize = 100000; if(is_uploaded_file($_FILES['image1']['tmp_name'])) { //check the file is less than the maximum file size if($_FILES['image1']['size'] < $maxsize) { //prepare the image for insertion $imgData =addslashes(file_get_contents($_FILES['image1']['tmp_name'])); $imgData = addslashes($_FILES['image1']); //get the image info.. $size = getimagesize($_FILES['image1']['tmp_name']); $id = $name.'_'.$SKU; //our sql query $sql = "INSERT INTO Images ( imageID , Type ,Image, Size, FileName, DateAdded, Category, SKU. Description) VALUES ('".$id."', '".$size['mime']."', '".$imgData."', '".$size[3]."', '".$_FILES['image1']['name']."', NOW(), Fabric, '".$SKU."', '".$desc."'"; echo $sql; // insert the image if(!mysql_query($sql)) { echo 'Unable to upload file'; } } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['image1']['name'].' is '.$_FILES['image1']['size'].' bytes</div> <hr />'; } at first the sql just wouldn't work. Now I get this error every time for some reason Quote File exceeds the Maximum File limit Maximum File limit is 100000 File Array is Array bytes which seems odd because it does not even return the file size or name correctly. Quote Link to comment https://forums.phpfreaks.com/topic/227919-image-upload-problem/ Share on other sites More sharing options...
BlueSkyIS Posted February 16, 2011 Share Posted February 16, 2011 you shouldn't store images in the database. you should save them as a regular file and store the image path/name in the database. but, anyway... this should be <input type="file" name="image1" /> Quote Link to comment https://forums.phpfreaks.com/topic/227919-image-upload-problem/#findComment-1175269 Share on other sites More sharing options...
vmicchia Posted February 17, 2011 Author Share Posted February 17, 2011 That worked. Thanks, there were a few more problems with the code but I got it figured out. I know it's not the best to put the image in the DB but it's what I was told to do. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/227919-image-upload-problem/#findComment-1175621 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.