Jump to content

Reading properties of a file

Recommended Posts

Hi all,


I am not sure if the Social Media forum is the right place for my question about serverside programming, but I will go ahead anyway.


I have a large number (thousands) of photos which I want to easily organise, by name, on my website. Programming the pages (day-by-day) is time-consuming.


I can use the glob() function in PHP to get a list of all of my JPG files in a specific sub-directory. I would like to also be able to read the dimensions for each individual photo so that I can have my PHP program write the appropriate sizing (height / width) on-the-fly.


However, I cannot seem to find a PHP function to read the dimensions. File size, yes; dimensions, no.


Is there a PHP function which I have missed, or a Javascript function, or...?


Thanks in advance.



Share this post

Link to post
Share on other sites

Mac, I'll be totally honest with you here...


PHP and Javascripting are not within my realm of competency, so I can't help you at all.


Stand by, though... there may be others around here who can help you with this.





Share this post

Link to post
Share on other sites

Hi ebrke,


Yes, that is it. I have to first ask myself why I did not immediately see that when I was looking at the Filesystem functions. Then, I see that it is not listed in the Filesystem Functions.


Thanks! I knew there was a function, just not exactly what it is.


All Hail Scot's Newletter Forums Participants!!



  • Like 1

Share this post

Link to post
Share on other sites

Hi All,


So, here is a followup on my intended use of the glob() function and the [pointed-out-to-me] getimagesize() function in PHP. Put the following code in an index.php (or whatever you want to call it) file in a directory with JPGs --


foreach (glob("*.jpg") as $filename)


$size = getimagesize ("$filename");

if ($size[3] == 'width="1772" height="1181"') :

echo "<img src=\"$filename\" height=118></P> ";

else :

echo "<img src=\"$filename\" height=177></P> ";


echo "$filename</P>&nbsp;</P> ";



This now reads the properties of all the JPGs and displays them according to the height found. I size all of the photos I upload as width=1772 / height-1181 or width=1181 / height=1772 according to whether the photo is horizontal or vertical. I have reduced the height by 10% to display the photo as a thumbnail. I will now enhance the code further for myself, displaying the photos in a TABLE with two-across CELLs. Obviously, the width and height sizes can be read and used dynamically when the hpotos are not saved with consistent dimensions.


This will now save me a lot of programming time. During the last Fasnacht season (what is know in other languages and regions as Carnival, Karneval, Mardi Gras and such), a six-week period of costumes, parties and parades, I shot more than 4,000 photos. I just did not want to deal with the program code for my own site and went to Facebook as a quick-and-dirty solution. Now, I will not have to.


Thanks again to ALL!



Edited by macdunn
  • Like 2

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...