Solved

Trying to get php function getimagesize working

Posted on 2012-03-18
6
483 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 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome.  I think it's just that PHP routine, not Godaddy.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:alexisbr
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
OK I understand now.  Thanks for the details.  I appreciate it.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to dynamically set the form action using jQuery.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now