Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
BLUE  
#1 Posted : Friday, March 19, 2010 9:11:02 AM(UTC)
BLUE

Rank: Member

Groups: Member
Joined: 3/16/2008(UTC)
Posts: 12

Is there an easy way to remove the spaces in an image

that is being uploaded the contains spaces?

my image.jpg ... becomes myimage.jpg

and is also reflected in the .xml file?

Thanks, Phil

Tamila  
#2 Posted : Friday, March 19, 2010 3:37:28 PM(UTC)
Tamila

Rank: Advanced Member

Groups:
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Phil,

You can do it on server-side. When you parse POST-request you can check whether file name has a space. If so, you can remove the space and save file in your file system with new name.

Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!

BLUE  
#3 Posted : Sunday, March 21, 2010 5:19:28 PM(UTC)
BLUE

Rank: Member

Groups: Member
Joined: 3/16/2008(UTC)
Posts: 12

Could you give me a little more data on how to get started on this?

I'm not sure where to begin...

I need to parse the .xml file's filename as well.

Replacing the space with an _ or - will work as well.

Whatever you send is much appreciated.

Thanks...

Edited by user Sunday, March 21, 2010 5:23:36 PM(UTC)  | Reason: Not specified

Tamila  
#4 Posted : Sunday, March 21, 2010 7:53:49 PM(UTC)
Tamila

Rank: Advanced Member

Groups:
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Phil,

The following code is modified BasicDemo upload.php script. It allows to replace space character with "_" in file name, thumbnail file name and write correct information in Description.xml:

Code:
<?php
require_once '../ImageUploaderPHP/UploadedFiles.php';

//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
$galleryPath = '../Gallery/';

$absGalleryPath = realpath($galleryPath) . '/';
$absThumbnailsPath = realpath($galleryPath . 'Thumbnails/') . '/';


function saveUploadedFiles() {
	global $absGalleryPath, $absThumbnailsPath;

	//Create XML file which will keep information about files (image dimensions, description, etc). 
	//XML is used solely for brevity. In real-life application most likely you will use database instead.	
	$descriptions = new DOMDocument('1.0');
	$descriptions->appendChild($descriptions->createElement('files'));
	
	//Iterate through uploaded data and save the original file, thumbnail, and description.
	while(($file = UploadedFiles::fetchNext()) !== null) {
		$fileName = $file->getSourceFile()->getSafeFileName($absGalleryPath);
		$correctFileName = str_replace(" ","_",$fileName);
		$file->getSourceFile()->save($absGalleryPath . '/' . $correctFileName);	
		
		$thumbFileName = $file->getThumbnail(1)->getSafeFileName($absThumbnailsPath);
		$correctThumbName = str_replace(" ","_",$thumbFileName);
		$file->getThumbnail(1)->save($absThumbnailsPath . '/' . $correctThumbName);
		
		//Save file info.
		$xmlFile = $descriptions->createElement('file');
		$xmlFile->setAttribute('name', $correctFileName);
		$xmlFile->setAttribute('thumbName', $correctThumbName);
		$xmlFile->setAttribute('width', $file->getSourceFile()->getWidth());
		$xmlFile->setAttribute('height', $file->getSourceFile()->getHeight());
		$xmlFile->setAttribute('description', $file->getDescription());
		$descriptions->documentElement->appendChild($xmlFile);
	}

	$descriptions->save($absGalleryPath . 'Descriptions.xml');	
}


function initGallery() {
	global $absGalleryPath, $absThumbnailsPath;
	
	//First of all, clear files and data uploaded at previous time.
	
	//Delete source files.
	$handle = opendir($absGalleryPath);

	while (false !== ($file = readdir($handle))) {
		if (is_file($absGalleryPath . $file)) {
			unlink($absGalleryPath . $file);
		}
	}
	closedir($handle); 

	//Delete thumbnails
	$handle = opendir($absThumbnailsPath);	
	while (false !== ($file = readdir($handle)))  {
		if (is_file($absThumbnailsPath . $file)) {
			unlink($absThumbnailsPath . $file);
		}
	}
	closedir($handle);
	
	//NOTE: If you do not want to delete previously uploaded files, just 
	//remove or comment out the code above.	
}


initGallery();
saveUploadedFiles();
?>

I hope it helps you.

Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!

BLUE  
#5 Posted : Tuesday, March 23, 2010 5:50:36 PM(UTC)
BLUE

Rank: Member

Groups: Member
Joined: 3/16/2008(UTC)
Posts: 12

Your are the best!!!!

Thank you.. Thank you.. Thank you!

Phil

elizas  
#6 Posted : Thursday, June 3, 2010 4:43:30 AM(UTC)
elizas

Rank: Newbie

Groups: Member
Joined: 6/3/2010(UTC)
Posts: 1

For us the following two file names may not hold much difference but when using CSS we have to take care of the space between the file names.

1. Page background.jpg

2. Page_background.jpg

For instance, to set a background image of a page using CSS we would have to add the following two lines of code -

background:#F7F9fa url(../Images/Page background.jpg);

background-repeat:repeat-x;

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.