Jump to content

[SOLVED] Image manipulation erros (reading image from mysql)


Recommended Posts

Hey iv got a form that lets a user upload an image, the image is then stored in a table called displaypic_$user.

I have a profile page for the user that calls on this image using <img src="ProfilePic.php" />  (the php page holds the script for resizing and displaying)

 

This was working fine when i was not tring to alter the images size. Iv now tried to alter the size of the image before displaying and get several error messages on the ProfilePic.php page.

 

Below is the code for the form that upoads the image

<?php

if ($submit) {

  

   $conn = mysql_connect("localhost","user","pass");
    mysql_select_db("user");

$sql0 = "DELETE FROM displaypic_$user WHERE id='1'";

$empty= @mysql_query($sql0, $conn )
or die(" Could not delete pic");



    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
    $id= "1" ;
    $result=mysql_query("INSERT INTO displaypic_$user (id,description,bin_data,filename,filesize,filetype) ".
        "VALUES ('$id','$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
} else {

    
?>

    <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
      <h5>Upload Picture 1</h5>
      Description for picture 1 <br>
          <input type="text" name="form_description"  size="40">
          <input type="hidden" name="MAX_FILE_SIZE" value="220000">
          <br>
        Choose image to upload for picture 1  (images must not be bigger than 200KB) <br>
        <input type="file" name="form_data"  size="40">
        </p>
      <p><input type="submit" name="submit" value="submit">
    </form>

<?php

}

?>

 

here is the code for ProfilePic.php that is used as the image source

<?php
$user = $_COOKIE['username'];
  @mysql_connect("localhost","user","pass");

    @mysql_select_db("user");

    $query = "select bin_data,filetype from displaypic_$user where id=1";
    $result = @mysql_query($query);

    $image = @mysql_result($result,0,"bin_data");
    $type = @mysql_result($result,0,"filetype");


$width = imagesx($image);
$height = imagesy($image);

$new_width = 150;
$new_height = 250;
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

   header("Content-Type: image/jpeg");
imagejpeg($image_resized);

?>

 

heres the error message profilepic.php shows

it seems to be pretty much saying that it cant do it to the file but the file is a jpeg so there is no reason it couldnt any help would be greatly appreciated cheers ;D

Warning: imagesx(): supplied argument is not a valid Image resource in /home/site23/public_html/thewu/ProfilePic.php on line 14

 

Warning: imagesy(): supplied argument is not a valid Image resource in /home/site23/public_html/thewu/ProfilePic.php on line 15

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/site23/public_html/thewu/ProfilePic.php on line 20

 

Warning: Cannot modify header information - headers already sent by (output started at /home/site23/public_html/thewu/ProfilePic.php:14) in /home/site23/public_html/thewu/ProfilePic.php on line 22

Resource id #3

 

 

 

 

 

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.