Jump to content

Image insertion and Retrieval


yandoo

Recommended Posts

Hi there,

 

I was hoping for a little help please?? Basically i have created 2 pages, addImage.php is the page that will allow the user to insert a record to the database dont through a basic form:

 

 <?php
      if ($_POST['Submit']) {
        if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
          //print_r($_FILES);
          mysql_connect("localhost", "root", "") or die(mysql_error());
          mysql_select_db("woodside");
          $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));
           $query = sprintf("INSERT INTO image(Image, FileType) VALUES
('%s', '%s')", $photo, $_FILES['file']['type']);
           if (mysql_query($query)) {
            $messages[] = "Your files is successfully store in database"; 
           } else {
            $messages[]= mysql_error();
           }
          } else {
           $messages[]="The file is bigger than the allowed size please resize";
          }
        }
      ?>
      <html>
      <head>
      <title>Add Image</title>
      </head>    
      <body>
      <?php 
      if (isset($messages)) { 
        foreach ($messages as $message) {
         print $message ."<br>";
        } 
      }
      ?>
      <form action="" method="post" enctype="multipart/form-data" name="form1">
      <input type="file" name="file">
      <input type="hidden" name="MAX_FILE_SIZE" value="96000">
      <input type="submit" name="Submit" value="Submit">
      </form>
      </body>
      </html>

 

The other page is Image.php, this is suposed to display the image from the database:

 

<?php require_once('Connections/woodside.php'); ?>
<?php ini_set('error_reporting',E_ALL); ?>
<?php 
  mysql_connect("localhost", "root", "") or die(mysql_error());
  mysql_select_db("woodside"); 

$result = mysql_query("SELECT ImageId from image");
while ($row = mysql_fetch_array($result)) {
$ids[]=$row['ImageId'];
}
?>
<html>
<head>
<title>Image Loader</title>
</head>

<body>
select image:<br>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10%">id</td>
<td width="90%">Image</td>
</tr>
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<? foreach ($ids as $id) { ?>
<tr>
<td><a href="?id=<?= $id; ?>"><?= $id; ?></a></td>
</tr>
<? } ?>
</table></td>
<td><? if (isset($_GET['id'])) { ?>
<img src="image.php?id=<?= $_GET['id']; ?>"><? } ?></td>
</tr>
</table>
</body>
</html>

 

 

Inserting animage works fine, it just when trying to view the images i have a problem. No images or any dyamic data is displayed, leaving on the titles id and image there :(

 

When i test out the page theres a shape of an image on the page but it has a cross through it???

 

Please see screenshot of what it looks like...

 

If anybody can help me please, that would be great, ive been stuck on this for ages now.

 

Thank You :)

Link to comment
https://forums.phpfreaks.com/topic/94696-image-insertion-and-retrieval/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.