Reading files with whitespaces in them

I need to read and resize images already on the server. Some of the files have spaces in the names which I can’t find a work around for.

For example: file_exists(‘image name.jpg’) returns false even though the file is there.

replacing the white spaces with an underscore is not an option. I need to be able to read the files.

Any ideas, thanks E.

I don’t think there should be any problems with spaces, try using the full path and check the file permissions.

I’ve done a test where I change a filename to remove the space and it works no problem. So I’m pretty sure this is the issue.

Here’s the complete code:

f

unction thumbnail_image($path){

	// Initial image uploading is handled by the ckfinder 
	// $path is the link returned by the ckfinder
	// microtime name is the name used to write the file to prevent overwriting
	
	
	if (count(explode( '/',$path)) > 1 ){
	
		if (file_exists($_SERVER['DOCUMENT_ROOT'].$path)){
			$name= str_replace(" ","", microtime()).".jpg";
			resize($path, IMAGE_FULL_WIDTH, "gallery/large/", $name);
			resize($path, IMAGE_THUMBNAIL_WIDTH, "gallery/thumbnail/", $name);

		} 

	}

	else { 
		$name=$path;
	}
	//exit;
	return $name;
}

function resize($path, $size, $directory, $microtime_name){
	 
	 $filename=$_SERVER['DOCUMENT_ROOT'].$path;
	// $plain_path=str_replace( '/images/userfiles/images/','',$path);
	//$plain_path=end(explode( '/',$path));

	// Get new sizes
	list($width, $height) = getimagesize($filename);
	if($width > $size){
	
	if ($width >= $height) {	$percentage=$size/$width; }
	else if ($width < $height) {	$percentage=$size/$height; }
	
		$newwidth = $width * $percentage;
		$newheight = $height * $percentage;
	
	}
	
	else {
		
		$newwidth = $width;
		$newheight = $height;
	
	}

		// Load
		$thumb = imagecreatetruecolor($newwidth, $newheight);
		$source = imagecreatefromjpeg($filename);

		// Resize
		imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

		// Output
		imagejpeg($thumb, $_SERVER['DOCUMENT_ROOT']."/images/$directory".$microtime_name)
			or die('could not create image');
		

	
}

What OS are you on? I’ve never heard of spaces affecting file functions.

I figured it out. Your comments pointed me in the right direction. I needed to urldecode the name. Thanks! E