Page 1 of 1

Using trim() function but getting odd results

Posted: Thu Jun 30, 2005 1:33 pm
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

Posted: Thu Jun 30, 2005 1:37 pm
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

Posted: Thu Jun 30, 2005 1:53 pm
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 />';
}
?>

Posted: Thu Jun 30, 2005 2:02 pm
by soianyc
Cool thanks for your help

Posted: Thu Jun 30, 2005 2:11 pm
by djot
if your question is answered, edit your subject of the first post to [SOLVED] ...