Solved

Trying to get php function getimagesize working

Posted on 2012-03-18
6
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 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 83

Expert Comment

by:Dave Baldwin
ID: 37738718
You're welcome.  I think it's just that PHP routine, not Godaddy.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 83

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

724 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