1

I am kinda new to configuring a apache/mysql server , but I have a problem . I have searched and searched all over the internet and I can't find anything that solves my problem. I have a site which uploads a form into my mysql database , my uploading php code works fine , because I have tested it, the thing is that in this form people can upload a maximum of 9 photos , everything works fine when you upload photos under 1 MB each , the thing is that every time someone uploads photos that added up exceeds 8 MB the form doesn't get uploaded . It's fine to upload , let's say 3 photos of 2 MB each , they will be uploaded , as long as the photos uploaded added up don't exceed 8 MB , now my question is : how can I increase the maximum memory of a row in my db to accept files that added up are larger than 8 MB , please help , thank you.

html code:

<div id="main">
    <p id="warn"><font>*</font> max 3 MB each photo</p>
    <p style="font-size:12px">Photo 1<input type="file" style="border:none;" name="image0" id="image0" g='image'></p>
    <p style="font-size:12px">Photo 2<input type="file" style="border:none;" name="image1" id="image1" g='image'></p>
    <p style="font-size:12px">Photo 3<input type="file" style="border:none;" name="image2" id="image2" g='image'></p>
    <p style="font-size:12px">Photo 4<input type="file" style="border:none;" name="image3" id="image3" g='image'></p>
    <p style="font-size:12px">Photo 5<input type="file" style="border:none;" name="image4" id="image4" g='image'></p>
    <p style="font-size:12px">Photo 6<input type="file" style="border:none;" name="image5" id="image5" g='image'></p>
    <p style="font-size:12px">Photo 7<input type="file" style="border:none;" name="image6" id="image6" g='image'></p>
    <p style="font-size:12px">Photo 8<input type="file" style="border:none;" name="image7" id="image7" g='image'></p>
    <p style="font-size:12px">Photo 9<input type="file" style="border:none;" name="image8" id="image8" g='image'></p>
</div>

php code :

$image0 = addslashes(file_get_contents($_FILES['image0']['tmp_name']));
$image1 = addslashes(file_get_contents($_FILES['image1']['tmp_name']));
$image2 = addslashes(file_get_contents($_FILES['image2']['tmp_name']));
$image3 = addslashes(file_get_contents($_FILES['image3']['tmp_name']));
$image4 = addslashes(file_get_contents($_FILES['image4']['tmp_name']));
$image5 = addslashes(file_get_contents($_FILES['image5']['tmp_name']));
$image6 = addslashes(file_get_contents($_FILES['image6']['tmp_name']));
$image7 = addslashes(file_get_contents($_FILES['image7']['tmp_name']));
$image8 = addslashes(file_get_contents($_FILES['image8']['tmp_name']));
$image_size = getimagesize ($_FILES['image0']['tmp_name']);
$image_size1 = getimagesize ($_FILES['image1']['tmp_name']);
$image_size2 = getimagesize ($_FILES['image2']['tmp_name']);
$image_size3 = getimagesize ($_FILES['image3']['tmp_name']);
$image_size4 = getimagesize ($_FILES['image4']['tmp_name']);
$image_size5 = getimagesize ($_FILES['image5']['tmp_name']);
$image_size6 = getimagesize ($_FILES['image6']['tmp_name']);
$image_size7 = getimagesize ($_FILES['image7']['tmp_name']);
$image_size8 = getimagesize ($_FILES['image8']['tmp_name']);


if ($image_size==TRUE && !empty($image0))   {
    $insert = mysql_query("UPDATE ".$tabla." SET pic1='".$image0."' WHERE id='$lastid'  " ) or die (mysql_error());     
}
if ($image_size1==TRUE && !empty($image1))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic2='".$image1."' WHERE id='$lastid'  " ) or die (mysql_error());     
}
if ($image_size2==TRUE && !empty($image2))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic3='".$image2."' WHERE id='$lastid'  " ) or die (mysql_error());
}
if ($image_size3==TRUE && !empty($image3))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic4='".$image3."' WHERE id='$lastid' " ) or die (mysql_error());
}
if ($image_size4==TRUE && !empty($image4))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic5='".$image4."' WHERE id='$lastid'  " ) or die (mysql_error()); 
}
if ($image_size5==TRUE && !empty($image5))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic6='".$image5."' WHERE id='$lastid'  " ) or die (mysql_error()); 
}
if ($image_size6==TRUE && !empty($image6))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic7='".$image6."' WHERE id='$lastid'  " ) or die (mysql_error());     
}
if ($image_size7==TRUE && !empty($image7))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic8='".$image7."' WHERE id='$lastid'  " ) or die (mysql_error()); 
}
if ($image_size8==TRUE && !empty($image8))  {
    $insert = mysql_query("UPDATE ".$tabla." SET pic9='".$image8."' WHERE id='$lastid'  " ) or die (mysql_error());     
}
jeff
  • 8,300
  • 2
  • 31
  • 43
southpaw93
  • 1,891
  • 5
  • 22
  • 39
  • 5
    check `post_max_size` in php.ini – Vatev Jul 22 '12 at 15:00
  • it was 8M , and I changed it to 64 M , but now the thing is when I upload the form , the form gets uploaded to the db but without the photos. – southpaw93 Jul 22 '12 at 15:05
  • there , I modified it so you can see the code in php that uploads the pcitures, again , I have no problem when uploading files under 1 MB , but when I uploaded like 9 photos of 6 MB each , the form gets uploaded without the photos. and I get this error in phpmyadmin : Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40473162 bytes) in C:\xampp\phpMyAdmin\tbl_replace.php on line 305 when trying to uploaded the photos in each field. – southpaw93 Jul 22 '12 at 15:14
  • can you send the code for the form as well? – bretterer Jul 22 '12 at 15:16
  • What is the format of the image column? – Mihai Stancu Jul 22 '12 at 15:18
  • it issue with your memory limit. check my answer below. you need to change it in your php.ini – varuog Jul 22 '12 at 15:20
  • well my memory_limit is 128M , post_max_size is 64M and I can't find upload_max_size inside php.ini file ,do I have to add it manually ? – southpaw93 Jul 22 '12 at 15:22
  • you should be using [mysql_real_escape_string](http://fr2.php.net/manual/en/function.mysql-real-escape-string.php) instead of `addslashes`. Even better, use [MySQLi](http://fr2.php.net/manual/en/class.mysqli.php) or [PDO](http://fr2.php.net/manual/en/class.pdo.php) functions, as all MySQL functions are going to be deprecated. – Jocelyn Jul 22 '12 at 15:39

2 Answers2

1

Plsssssssssss, do not store images in your database i repeat, do not store images in your database. I suggest you research on why but i can give you a few heads up now;

  1. Your database will be filled up heavily in a short time. this affects backups.
  2. you cannot use cdn when things become out of hand.
  3. It takes more time getting the image from your database out to the screen than just linking to it.

If the image has restrictions, store them outside the web root.

You should try and research more

Spikes
  • 176
  • 2
  • 6
  • thank you for the heads up , I decided that it's better to store the photo on my server in a folder , and retain the address inside the db , it's much faster and easier this way :) – southpaw93 Jul 22 '12 at 15:56
0

http://www.php.net/manual/en/ini.core.php#ini.post-max-size check this

'post_max_size",upload_max_size"."memory_limit" need to be increased

varuog
  • 3,031
  • 5
  • 28
  • 56
  • he can try putting the images in the database one by one to avoid the memory limit issue. – Vatev Jul 22 '12 at 15:19
  • yes, he can but if he wants to do multiple file upload with larger memory there is no other way than this. – varuog Jul 22 '12 at 15:22