?
Solved

Trying to get php function getimagesize working

Posted on 2012-03-18
6
Medium Priority
?
549 Views
Last Modified: 2012-03-19
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
0
Comment
Question by:alexisbr
  • 3
  • 3
6 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 37736184
The code works perfectly on my server here with both a file in the same directory and a file on my hosted web site.  Since your code is loading the image, there is something about your path that one of the routines doesn't like.  Try putting the image file in the same directory as the PHP file and see if it works.
0
 

Author Comment

by:alexisbr
ID: 37737055
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
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37738718
You're welcome.  I think it's just that PHP routine, not Godaddy.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:alexisbr
ID: 37739046
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
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37739365
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.
0
 

Author Comment

by:alexisbr
ID: 37739370
OK I understand now.  Thanks for the details.  I appreciate it.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question