mmarif4u Posted December 19, 2007 Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/82275-getimagesize-not-working/ Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 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 https://forums.phpfreaks.com/topic/82275-getimagesize-not-working/#findComment-418218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.