Solved

GetImageSize(): Why isn't this working?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File submission to SQL Server 1 37
Amazon Redshift 2 24
RELATED: How do I fix this error:  Warning: strpos(): Empty needle on line 122 11 32
php string masking 4 27
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

932 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

12 Experts available now in Live!

Get 1:1 Help Now