Jump to content

Problem Uploading Images to MySQL database


denhamd2

Recommended Posts

Hi,

I have a problem with my image upload form. When I upload a large image to my MySQL database it tells me it has uploaded ok, but when I go and view it it was only partially uploaded, ie. only the top of the image shows. Smaller images upload fine. Would anyone have any idea what might be going wrong?

Here's my PHP image upload code:

[code=php:0]$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));   

if ($img1_type == "image/gif" ) {  if ($img1_size < 3000000) { 
$insert_data = "INSERT INTO  tblimage (TechID, binary_junk, filename, filesize, filetype)  VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')"; 
@mysql_query($insert_data)
or  die("The image is either not a valid GIF or is above 2.9MB, thus could not be added.");  }  }

elseif ($img1_type == "image/jpeg") { 
if ($img1_size < 3000000) { 
$insert_data = "INSERT INTO  tblimage (TechID, binary_junk, filename, filesize, filetype)  VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')"; 
@mysql_query($insert_data)
or  die("The image is either not a valid JPEG or is above 2.9MB, thus could not be added.");  }  }

elseif ($img1_type == "image/pjpeg") { 
if ($img1_size < 3000000) { 
$insert_data = "INSERT INTO  tblimage (TechID, binary_junk, filename, filesize, filetype)  VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')"; 
@mysql_query($insert_data)
or  die("The image is either not a valid JPEG or is above 2.9MB, thus could not be added.");  }  }[/code]


Here is my PHP code to view the image:
[code=php:0]$get_image = "select binary_junk,   
filetype from tblimage where img_id = $fileid";   
$get_image_result = @mysql_query($get_image)   
or die("Couldn't get image.");   
$binary_junk = @mysql_result  ($get_image_result,0,"binary_junk");   
$filetype = @mysql_result  ($get_image_result,0,"filetype");   

header("Content-type: $filetype");   

echo "$binary_junk";[/code]




Many thanks in advance
Link to comment
Share on other sites

do you have the MAX UPLOAD directives set in the upload form?
do you have max upload set in PHP.ini
Is the table and cells where you want to put this stuff have any limitations?
~~best thing to do is set the  cell feild varchar(3000000)~~
check if your host allows that big file uploads.
Link to comment
Share on other sites

here is all the code i used. if someone could have a look and check it is ok id be very grateful:

HTML Form Page:
[CODE]
<?php require_once('../Connections/capital.php'); ?><?php
mysql_select_db($database_capital, $capital);
$query_productid = "SELECT * FROM properties ORDER BY propertyid DESC";
$productid = mysql_query($query_productid, $capital) or die(mysql_error());
$row_productid = mysql_fetch_assoc($productid);
$totalRows_productid = mysql_num_rows($productid);
?>
<HTML>
<HEAD>
<TITLE></TITLE>
<link href="../adminstyle.css" rel="stylesheet" type="text/css">
</HEAD>

<BODY>
<table width="750" align="center">
  <tr>
    <td></td>
  </tr>
  <tr>
    <td><?php include('nav_inc.php'); ?>
      <h1>Add Photo</h1>
        <FORM action="image_add_2.php"
method="post" enctype="multipart/form-data" name="prod_img" id="prod_img">
          <p>  Choose file to use as a photo for this property: <br>
            <INPUT type="file" name="img1" size="30">
            <input name="propertyid" type="hidden" id="propertyid" value="<?php echo $row_productid['propertyid']; ?>">
  </p>
          <p>
            <INPUT type="submit" name="submit"
value="Submit">
          </p>
    </FORM></td></tr>
</table>
</BODY>
</HTML>
<?php
mysql_free_result($productid);
?>

[/CODE]


Image Upload PHP Page:
[CODE]<?
  Header('Cache-Control: no-cache');
  Header('Pragma: no-cache');
  ?>
<?php require_once('../Connections/capital.php'); ?><?php
mysql_select_db($database_capital, $capital);
$query_Recordset1 = "SELECT * FROM tblimage ORDER BY img_id DESC";
$Recordset1 = mysql_query($query_Recordset1, $capital) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_capital, $capital);
$query_get_latest_property = "SELECT * FROM properties ORDER BY propertyid DESC";
$get_latest_property = mysql_query($query_get_latest_property, $capital) or die(mysql_error());
$row_get_latest_property = mysql_fetch_assoc($get_latest_property);
$totalRows_get_latest_property = mysql_num_rows($get_latest_property);
?>
<?



$db = @mysql_connect($hostname_capital,
$username_capital, $password_capital) or
die("Can't connect to server.");
@mysql_select_db($database_capital, $db) or
die("Can't select database.");


$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));

if ($img1_type == "image/gif" ) {
if ($img1_size < 3000000) {
$insert_data = "INSERT INTO
tblimage (TechID, binary_junk, filename, filesize, filetype)
VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($insert_data) or
die("The image is either not a valid GIF or is above 2.9MB, thus could not be added.");
}
} elseif ($img1_type == "image/jpeg") {
if ($img1_size < 3000000) {
$insert_data = "INSERT INTO
tblimage (TechID, binary_junk, filename, filesize, filetype)
VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($insert_data) or
die("The image is either not a valid JPEG or is above 2.9MB, thus could not be added.");
}
} elseif ($img1_type == "image/pjpeg") {
if ($img1_size < 3000000) {
$insert_data = "INSERT INTO
tblimage (TechID, binary_junk, filename, filesize, filetype)
VALUES ('$propertyid', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($insert_data) or
die("The image is either not a valid JPEG or is above 2.9MB, thus could not be added.");
}
}
?>
<?php $thefileid = $row_Recordset1['img_id'] + 1; ?>
<link href="../adminstyle.css" rel="stylesheet" type="text/css">
<table width="750" align="center">
  <tr>
    <td></td>
  </tr>
  <tr>
    <td><?php include('nav_inc.php'); ?><h1>Property Photo </h1>
      <p><?php echo "<a href=\"image_add_3.php?fileid=$thefileid\" target=\"_blank\">View what
            you uploaded</a>"; ?></p>
    <?php
mysql_free_result($Recordset1);

mysql_free_result($get_latest_property);
?>
    <form name="form1" method="post" action="image_add_4.php">
      <div align="center">
        <input name="id" type="hidden" id="id" value="<?php echo $row_get_latest_property['propertyid']; ?>">
        <input type="submit" name="Submit" value="Add Another Photo For This Property">
      </div>
    </form></td>
  </tr>
</table>
[/CODE]


Any help would be much appreciated.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.