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
|
|
|
|
Rank: Advanced Member
Groups: Member
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.
|
|
|
|
|
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
|
|
|
|
Rank: Advanced Member
Groups: Member
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. |
|
|
|
|
Rank: Member
Groups: Member
Joined: 3/16/2008(UTC) Posts: 12
|
Your are the best!!!!
Thank you.. Thank you.. Thank you!
Phil
|
|
|
|
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;
|
|
|
|
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.