Jump to content

Getimagesize() not working


mmarif4u

Recommended Posts

Hi to all..

I am using the getimagesize() function to resize and get the image dimensions and it seemed to be not working for images with space.

 

list($w,$h)=getimagesize($image);
$fixw='500';
$fixh='450';
if($w > $fixw ){
$w='500';}
if ($h > $fixh){
$h='450';
}

I am retrieving image name from database and then use the dir structure to show images.

Now the above function works well for the images name like:my_pic.jpg,pic.jpg.

But if the image name is:my pic.jpg ,so the function will not resize the image.

I cant rename images like:my_pic.jpg.Bcoz the prev programer did not use any function to change the image name to some valid name.Now i change the upload script and use str_replace to remove spaces.But i am worrying about the images already on server with spaces.

 

I need some lite help,how to enhance the function to work for images with spaces.

Any help will appreciated.

TQ

 

Link to comment
Share on other sites

Do this

 

<?php
// open the current directory
$dhandle = opendir('images/');
// define an array to hold the files
$files = array();

if ($dhandle) {
   // loop through all of the files
   while (false !== ($fname = readdir($dhandle))) {
      // if the file is not this file, and does not start with a '.' or '..',
      // then store it for later display
      if (($fname != '.') && ($fname != '..') &&
          ($fname != basename($_SERVER['PHP_SELF']))) {
          // store the filename
          $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
      }
   }
   // close the directory
   closedir($dhandle);
}

// Now loop through the files, echoing out a new select option for each one
foreach( $files as $fname )
{
str_replace(" ","_","{$fname}");
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.