I tried using:
pathinfo($upload_dir.$filename);
echo $path_parts['basename'], "\n";
and I get this on the Linux:
C:\Documents and Settings\trevorj\Desktop\image.jpg
Here is the code
<?php
//Chmod it (777)
$upload_dir = "images/"; //change to whatever you want.
// files less than 1MB
$size_bytes = 1048576; //bytes will be uploaded
//check if the directory exist or not.
if (!is_dir("$upload_dir")) {
die ("The directory <b>($upload_dir)</b> doesn't exist");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
}
//Check first if a file has been selected
//is_filetoupload_file('filename') returns true if
//a file was filetoupload via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
echo "File Too Large. Please try again.";
exit();
}
// $filename will hold the value of the file name submetted from the form.
$filename = $FILES['filetoupload']['name'];
$tmp_filename = $FILES['filetoupload']['tmp_name'];
// Check if file is Already EXISTS.
if(file_exists($upload_dir.$filename)){
echo "Oops! The file named <b>$filename </b>already exists";
exit();
}
//Move the File to the Directory of your choice
//move_filetoupload_file('filename','destination') Moves an filetoupload file to a new location.
if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
//tell the user that the file has been filetoupload
echo "File (<a href=$upload_dir$filename>$filename</a>) uploaded!<br>";
$path_parts = pathinfo($upload_dir.$filename);
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
}
else
{
//Print error
echo "There was a problem moving your file";
exit();
}
}
?>