Avatar of alexisbr
alexisbr
 asked on

Trying to get php function getimagesize working

resulting page from code and errorHi.  I have been trying to get this to work for hours.  I can't see what I am doing wrong.  I am working on php4 on godaddy shared hosting.  I am trying to get the php function getimagesize working in a test php program so I can apply the logic to another program.

I displayed the file variable with an img tag to confirm the path to the image file was correct.

Here's my test page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$filename = "/webadmin/uploads_for_emails/smileyface.jpg";
echo "<img src='" . $filename . "'>";
echo "filename " . $filename;
list($width, $height, $type, $attr) = getimagesize($filename);

echo "Image width " .$width;
echo "<BR>";
echo "Image height " .$height;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;

?>
</body>
</html>

Open in new window


I've attached a screenshot of the resulting page and error message.

Thanks for your help.
Alexis
PHP

Avatar of undefined
Last Comment
alexisbr

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
alexisbr

ASKER
Thanks, Dave.  You are right.  The problem was with the path.  When I tried putting the image in the same folder, it worked.  Apparently the routines don't like when you use the path from root.  I changed the path to start from the current folder, and then it worked.  Here's the change below that worked for both displaying the image and giving the width and height.  

$filename = "/webadmin/uploads_for_emails/smileyface.jpg";
to
$filename = "uploads_for_emails/smileyface.jpg";

I'm not sure why godaddy doesn't accept the other path but I'm glad to know how to get it to work.

Thank you again for your awesome help.

Alexis
Dave Baldwin

You're welcome.  I think it's just that PHP routine, not Godaddy.
alexisbr

ASKER
Thanks, Dave but I thought you said my original program worked fine as is on your system and on your host.  That's why I was saying the problem must be on godaddy's end that I had to change the way I did the paths.

Alexis
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Dave Baldwin

The first thing I did with your code is change the image link to one in the same directory.  Then I changed it to an image on my web site.  Both worked fine so I figured it must be the path.  But your path worked to display the image but not with the getimagesize() function.  So the path worked in an <img> tag but not in the PHP function.  Both are still coming from Godaddy so I don't think it's a Godaddy problem.  Just some oddity in the way PHP was trying to use the path.
alexisbr

ASKER
OK I understand now.  Thanks for the details.  I appreciate it.