i have code for uploading images to my website on my computer, and it works fine, but when I tried to set up the same site on another computer, and a remote server, the images were not coming up.
Any suggestions? Below is the code for
uploading and viewing:

code for creating the thumbnail:

<?php
function getThumb($Original)
{
   if (!$Original['name'])
   {
      //no image supplied, use default
      $TempName = "images/noimage.jpg";
      $TempFile = fopen($TempName, "r");
      $thumbnail = fread($TempFile, fileSize($TempName));
   } else
   {
      //get image
      $Picture =  file_get_contents($Original['tmp_name']); //reads temp file on server into PHP string var
      //create image
      $SourceImage = imagecreatefromstring($Picture); //creates image from string
      if (!$SourceImage)
      {
         //not a valid image
        echo "Not a valid image\n";
        $TempName = "images/noimage.jpg";
        $TempFile = fopen($TempName, "r");
        $thumbnail = fread($TempFile, fileSize($TempName));
      } else
      {
         //create thumbnail
         $width = imageSX($SourceImage);
         $height = imageSY($SourceImage);
         $newThumb = imagecreatetruecolor(80, 60); //formats thumb to specific size

     //resize image to 80 x 60
     $result = imagecopyresampled($newThumb, $SourceImage, 
                                  0, 0, 0, 0,
                                  80, 60, $width, $height);

     //move image to variable
     ob_start(); //creates output buffer that stores content
     imageJPEG($newThumb); //usually outputs image to browser, here redirects to output area
     $thumbnail = ob_get_contents(); //retrieves the content from the buffer area
	 								//stores string value into a PHP string var
     ob_end_clean();  // stops the buffering
  }
   }
   return $thumbnail;
}?>

Code for viewing the thumbnail:

<?php

error_reporting(E_ALL);


   header("Content-type: image/jpeg");
   $prodid = $_GET['id'];
   $con = mysql_connect("localhost", "test", "test") or die('');
   mysql_select_db("store", $con);

   $query = "SELECT picture from products WHERE prodid = $prodid";
   $result = mysql_query($query);
   $row = mysql_fetch_array($result, MYSQL_ASSOC);
   $picture = $row['picture'];
   echo $picture;
?>
<?php

error_reporting(E_ALL);

include("mylibrary/login.php");
login();
$query = "SELECT prodid, description FROM products";
$result = mysql_query($query) or die(mysql_error());

echo "<table width=\"50%\" cellpadding=\"1\" border=\"1\">\n";
echo "<tr><td>Product ID</td><td>Description</td><td>Image</td></tr>\n";
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
   $prodid = $row['prodid'];
   $description = $row['description'];

   echo "<tr><td>$prodid</td><td>$description</td>\n";
   echo "<td><img src=\"showimage.php?id=$prodid\" width=\"80\" height=\"60\"></td></tr>\n";
}
echo "</table>\n";
?>

    What do the rows in the MySQL table look like after you attempted to upload images to the remote site?

    Also, you should be checking to make sure that the file upload went successfully before attempting to use any uploaded file(s). You can then use the constants found on the manual page ([man]file-upload.errors[/man]) to output/log an appropriate error message if necessary.

      I checked the mysql table, and the images do seem to be uploading successfully, there is a medium blob created in the picture field. But the images are not coming up when I run the imagetest file. This seems to be the main problem.

        wallys12345;10984134 wrote:

        I checked the mysql table, and the images do seem to be uploading successfully, there is a medium blob created in the picture field.

        Did you happen to notice if it actually contained any data or if it was 0 bytes in length?

        wallys12345;10984134 wrote:

        But the images are not coming up when I run the imagetest file.

        And is that this code:

        <?php 
        
        error_reporting(E_ALL); 
        
        
           header("Content-type: image/jpeg"); 
           $prodid = $_GET['id']; 
           $con = mysql_connect("localhost", "test", "test") or die(''); 
           mysql_select_db("store", $con); 
        
           $query = "SELECT picture from products WHERE prodid = $prodid"; 
           $result = mysql_query($query); 
           $row = mysql_fetch_array($result, MYSQL_ASSOC); 
           $picture = $row['picture']; 
           echo $picture; 
        ?>

        you're talking about?

        Try commenting out the header() line (so you can view the raw contents of the page without your browser trying to render image data for you instead) and echo'ing out that $query SQL query - does it look right? If you execute it manually (e.g. via CLI or phpMyAdmin) does it SELECT the row you're after?

        Also, do you see the binary data (which won't look like anything recognizable, of course) when you visit that page? (If not, did you remember to pass the 'prodid' value in the URL when viewing that page? :p)

          yes, here is what is in the field: [BLOB - 2.0KiB], and yes that is the code. I commented out the header line, but the page still comes up normal, no binary data, with the table listing the id and description, so the prodid values seem to be working, but question mark for the image .

            wallys12345 wrote:

            the page still comes up normal, no binary data, with the table listing the id and description

            Er wait, it sounds like you're viewing the page that outputs the HTML table with the data.

            I was asking if you had tried visiting the showimage.php page directly (with a valid prodid supplied via the query string, of course) after commenting out the header() lines to see if PHP was outputting any error messages. Speaking of error messages, do you have display_errors set to On?

              He is the showimage.php code that I ran directly. Just got a blank page. I do have errors turned on. I commented out the header, and plugged in an actual prodid.

              <?php
              //header("Content-type: image/jpeg");
              $prodid = $_GET['id'];
              $con = mysql_connect("localhost", "test", "test") or die('');
              mysql_select_db("store", $con);

              //$query = "SELECT picture from products WHERE prodid = $prodid";
              $query = "SELECT picture from products WHERE prodid = 1";
              $result = mysql_query($query);
              $row = mysql_fetch_array($result, MYSQL_ASSOC);
              $picture = $row['picture'];
              echo $picture;
              ?>

                I did so and got the word NULL. Here is the code:

                <?php
                //header("Content-type: image/jpeg");
                $prodid = $_GET['id'];
                $con = mysql_connect("localhost", "test", "test") or die('');
                mysql_select_db("store", $con);

                //$query = "SELECT picture from products WHERE prodid = $prodid";
                $query = "SELECT picture from products WHERE prodid = 1";
                $result = mysql_query($query);
                $row = mysql_fetch_array($result, MYSQL_ASSOC);
                $picture = $row['picture'];
                echo $picture;

                var_dump($row);
                ?>

                  my mistake I did have errors turned off. This is the message I got.

                  Notice: Undefined index: id in /Users/macowner/Sites/jillStore3/admin/showimage.php on line 3

                  Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Users/macowner/Sites/jillStore3/admin/showimage.php on line 10
                  NULL

                    The first error is obviously the root of your problems. Did you not include the 'id' parameter in the query string when you accessed that page?

                      Write a Reply...