Using trim() function but getting odd results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Using trim() function but getting odd results

Post by soianyc »

I have a filename that i want to use, so i can make a directory for those particular files. I setup my code as follows

Code: Select all

<?php

$filename = '15408front.jpg';
$percent = .75;
$pathname = trim($filename, '.jpg');

$path = '/' + $pathname;


if(!file_exists($path)){

mkdir($path);
echo 'Directory '.$path.' Created';

}else{

echo 'Directory already exists <br />';

}

?>
When i run this script i get a directory of 15408, which is the numeric value of the string. Oddly when i tried taking the numbers out, i get a directory named 0. From what i have read and gathered im using this string correctly. Is there anything you can see wrong here??

As always your responses are greatly appreciated.


Regards

-soianyc
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

$path = '/'.$pathname;

Why do you create folders from filenames?

what about using function basename()?
http://de3.php.net/manual/en/function.basename.php
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

Code: Select all

<?php
$filename = '15408front.jpg';
$percent = .75;
$pathname = basename($filename, '.jpg');
//$pathname = trim($filename, '.jpg');

//$path = '/'.$pathname;
// or do you want to create a folder in the current directory?
$path = './'.$pathname;

if(!file_exists($pathname)){
@mkdir($pathname);
echo 'Directory '.$pathname.' Created';
}else{
echo 'Directory already exists <br />';
}
?>
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post by soianyc »

Cool thanks for your help
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

if your question is answered, edit your subject of the first post to [SOLVED] ...
Post Reply