Solved

GetImageSize(): Why isn't this working?

Posted on 2001-07-10
5
270 Views
Last Modified: 2012-06-21
I'm trying to figure out the size of an image.  According to the PHP manual, I have to use the GetImageSize() function.

Well, for some reason, it's not working.  Here's my coding:

<?PHP
$size = GetImageSize("/userpics/sslcg.jpg"); // LINE 2
//print "<img src=\"/userpics/sslcg.jpg\">";
//The above line printed the picture correctly.
?>

I know that this picture exists in the userpics directory and everything is spelled correctly.  Below is the error I get:

Warning: Unable to open /userpics/sslcg.jpg in /var/www/html/test.php on line 2

I'm a little puzzled.  Can you someone help me out?

Thanks,
Mike
0
Comment
Question by:myuen
5 Comments
 
LVL 1

Expert Comment

by:anupkarade
ID: 6272060
hi...
   try this different approch...

Please follow these steps    

1. Paste this code in a file
it contains the browse button for Image selection
and a submit button.


<HTML>
<HEAD>
<TITLE>Upload example</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION="resultUpload.php" ENCTYPE="multipart/form-data">

<p><strong>File</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Send"></p>

</FORM>

</BODY>
</HTML>


::Step 2

resultUpload.php
this is the page you called on submission
here you get all the image related properties...
<?
   print("$img1_type <BR>");
   print("$img1_size <BR>");
?>



:: If you want to open the image on an button click event
   or a href use the javascript function

   window.open('Yourpage.php','Window Name','toolbar=no location =no,addressbar=no');

::: Then in the Yourpage.php paste the following script

<?
   print("<HTML>");
   print("<HEAD>");
  print("<TITLE>Image</TITLE>");
  print("</HEAD>");
  print("<BODY>");
   
  print("<img src=".\Yourimage.jpg">")  
  print("</BODY>");
  print("</HTML>");

?>
   
Also note that you can set the height,width and position of window and image as well

               
                         regards
                                Anup


0
 
LVL 8

Expert Comment

by:us111
ID: 6272168
where's this folder : /userpics ? in /var/www/html/ ???
0
 
LVL 1

Author Comment

by:myuen
ID: 6272973
The directory structure is as follows for the sslcg.jpg picture I want to open:

/var/www/html/userpics/sslcg.jpg
0
 
LVL 1

Expert Comment

by:manucorp
ID: 6274050
<?PHP
$size = GetImageSize("/userpics/sslcg.jpg"); // LINE 2
//print "<img src=\"/userpics/sslcg.jpg\">";
//The above line printed the picture correctly.
?>

give up the / else you are an absolute file description

<?PHP
$size = GetImageSize("userpics/sslcg.jpg"); // LINE 2
//print "<img src=\"/userpics/sslcg.jpg\">";
//The above line printed the picture correctly.
?>

if file is /var/www/html/test.php

if you want to be sure

<?PHP
$size = GetImageSize("/var/www/html/userpics/sslcg.jpg"); // LINE 2
//print "<img src=\"/userpics/sslcg.jpg\">";
//The above line printed the picture correctly.
?>

0
 

Accepted Solution

by:
roglewis earned 50 total points
ID: 6275061
Whenever you reference a file from PHP (whether through GetImageSize or ReadFile or whatever), you need to provide the full file name, not just it's location under the document root.

Understand that PHP is installed on the machine, and it will access files as if you referenced them from a command line.  It is NOT limited to accessing the webserver's document root, which is one of the things that makes PHP so cool.

In your above code, the correct call would be:
$size = GetImageSize("/var/www/html/userpics/sslcg.jpg");

Assuming that the DocumentRoot of your webserver is "/var/www/html", you can also use:
$size = GetImageSize($DOCUMENT_ROOT."/userpics/sslcg.jpg");

that's your answer!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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.

708 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

19 Experts available now in Live!

Get 1:1 Help Now