Jump to content

Images - 0px?


Tiruak

Recommended Posts

Alright, so I'm having a problem that I can't figure out by my self.

I'm just testing a way to display an image. It's not really the application, I'm just making tests with the database.

So, I have a table with a medium blob field that contain an image (it's a protrait, very small, less then 100kb).

 

I'm just trying to test it, so I did write a showpic.php script to test it. it follows...

 

$user_id = 10;
mysql_connect("localhost","user","pass");
mysql_select_db("my_db");
$q = "select * from my_table where id = '$user_id'";
$r = mysql_query($q);
$rset = @mysql_fetch_assoc($r);
$imagebytes = $rset[arb_photo];

header("Content-type: image/jpeg");
print $imagebytes;

 

So, I was expecting this to just print the image.

What I get instead, is just the web address where the script is, as if it was a broken image. The page title shows

 

showpic.php (JPEG Image)

 

and on the place where the image is supposed to be it shows

 

http://localhost/site/showpic.php

 

 

When I right click on the "http://localhost/site/showpic.php", it's not a text, it's an image, and when I right click it to see the "View image info" option, it gives me the following:

 

Location: http://localhost/agat/members/showpic.php

Type: JPEG image

Size: 62,91 KB (64.415 bytes)

Dimensions: 0px × 0px (scaled to 256px × 19px)

 

I'm pretty sure it's something related to the dimensions (duh), but I'm not sure what it is.

 

Can anyone help, and show how dumb am I?

 

Thanks in advance! :)

Link to comment
Share on other sites

I don't think the problem has anything to do with image dimensions. You are suppressing errors on your database functions. So, if there are any errors you won't see them. You are also not referencing the field correctly in the results. The field name should be in quotes. But, even though it is not correct, it has been my experience it will work anyway.

 

Try the following:

$user_id = 10;
mysql_connect("localhost", "user", "pass");
mysql_select_db("my_db");
$q = "SELECT * FROM my_table WHERE id = '$user_id'";
$r = mysql_query($q);
if(!$result)
{
    echo "Error running query:<br />{$q}<br />Error:<br />" . mysql_error();
}
else
{
    $rset = mysql_fetch_assoc($r);
    $imagebytes = $rset['arb_photo'];

    header("Content-type: image/jpeg");
    print $imagebytes;
}

 

If that doesn't work, do a print_r() on $rset to verify the database results

Link to comment
Share on other sites

I don't think the problem has anything to do with image dimensions. You are suppressing errors on your database functions. So, if there are any errors you won't see them. You are also not referencing the field correctly in the results. The field name should be in quotes. But, even though it is not correct, it has been my experience it will work anyway.

 

Try the following:

 

code

 

If that doesn't work, do a print_r() on $rset to verify the database results

 

Well, I did try that, and it doesn't give me any errors. I did print the array, and it give me all the fields, including all the "’����ª��’ ����²��’����º��’������� ’����Y��� ’����Â��†’���Ê��� ����0100 �������"  of the blob field.

 

Now I'm starting to think that it could have something to do with the way I stored the image on the database. I will try to reproduce here, so maybe you can point some mistake for me (btw, I did check the table on phpmyadmin, and the blob field have the image there).

 

Here is what I have on my "insert_form" (I will post only what I think is relevant):

 

<form enctype="multipart/form-data">

<input type="hidden" name="MAX_FILE_SIZE" value="1000000"  />

<input type="file" name="photo" id="photo" />

 

Now on my receiving script, I have the following:

 

	if (isset($_FILES['photo'])) {
	// begin the image handling code
	$errors = array();
	try {
		if (!array_key_exists('photo', $_FILES)) {
            	throw new Exception('Image not found as upload');
        	}

        	$image = $_FILES['photo'];

        	// ensure the file was successfully uploaded
        	assertValidUpload($image['error']);

        	if (!is_uploaded_file($image['tmp_name'])) {
            	throw new Exception('File is not an upload.');
        	}

        	$info = getImageSize($image['tmp_name']);

        	if (!$info) {
            	throw new Exception('File is not an image.');
        	}
    	}
    	catch (Exception $ex) {
        	$errors[] = $ex->getMessage();
    	}

    	if (count($errors) == 0) {
        	// no errors, so insert the image
        	$foto = mysql_real_escape_string(file_get_contents($image['tmp_name']));
		$mime = mysql_real_escape_string($image['mime']);
     	}
} else { $foto = " "; $mime = " "; }

 

then, after processing some other fields, I have:

 

$query = "INSERT INTO table (arb_photo, mime_type) VALUES ('{$foto}', '{$mime}')";
$result = mysql_query($query, $connection);

 

So that's all the info I think is relevant.

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.