Given:
function upload($file_id, $destination) {
$folder = "/uploads";
$types = "jpg, jpeg, gif, tiff, png";
if (! $_FILES [$file_id] ['name'])
return false;
$fileName = $_FILES [$file_id] ['name'];
if (! testExtensions ( $fileName, $types )) {
echo ("<p>FAILED TEST EXTENSIONS</p>");
return false;
}
$uniqer = substr ( md5 ( uniqid ( rand (), 1 ) ), 0, 5 );
$fileName = $uniqer . '_' . $fileName; // Get Unique Name
$path = getPath ( $destination ) . "/";
$uploadFile = $path . $fileName;
if (! move_uploaded_file ( $_FILES [$file_id]['tmp_name'], $uploadfile )) {
return false;
} else {
if (! $_FILES [$file_id] ['size']) { // Check if the file is made
@unlink ( $uploadfile ); // Delete the Empty file
$file_name = '';
return false;
} else {
chmod ( $uploadfile, 0777 ); // Make it universally writable.
}
}
return $file_name;
}
function getPath($destination) {
$path = getcwd ();
$pathParts = explode ( "/", $path );
array_pop ( $pathParts );
array_push ( $pathParts, $destination );
$path = implode ( "/", $pathParts );
return $path;
}
function testExtensions($fileName, $types) {
$extensions = split ( "\.", basename ( $fileName ) );
$extension = strtolower ( $extensions [count ( $extensions ) - 1] ); // Get the last extension
$all_types = explode ( ",", strtolower ( $types ) );
if ($types) {
if (! in_array ( $extension, $all_types ))
return false;
}
return true;
}
is there any way to test why move_uploaded_file failed? I've generated some trace output to make sure that everything makes sense, but all of the output seems to suggest that move_uploaded_file should be working. However, the function consistently returns false.