Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetImageSize(): Why isn't this working?

Posted on 2001-07-10
5
Medium Priority
?
325 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 200 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

Technology Partners: 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

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‚Ķ
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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