Solved

GetImageSize(): Why isn't this working?

Posted on 2001-07-10
5
310 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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