I have tried everything but it won't upload any other format unless I take the limits off, but I am not going to do that.
Heres the code :
<?PHP
require_once 'includes/inc.php';
connect();
$settings = new settings();
// this is the upload dir where files will go.
//Don't remove the /
//Chmod it (777)
$upload_dir = $settings->urltodir; //change to whatever you want.
// files less than 1MB
$size_bytes = $settings->filemax; //bytes will be uploaded
$limit_file_type = "yes"; //Do you want to limit the types of files uploaded. (yes/no)
// specify file types.
$allowed_file_type = array('image/gif',
'image/pjpeg',
'image/jpeg',
'image/png',
'image/jpg',
'image/bmp',
'text/java',
'text/plain',
'application/msword',
'application/pdf',
'application/zip application/x-zip-compressed',
'application/x-rar-compressed application/octet-stream',
'audio/x-mp3',
'text/cpp application/octet-stream');
switch($_FILES['filetoupload']['type'])
{
case 'audio/x-mp3':
$type = "mp3";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'text/cpp application/octet-stream':
$type = "cpp";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'application/msword':
$type = "doc";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'application/pdf':
$type = "pdf";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'application/zip application/x-zip-compressed':
$type = "zip";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'application/x-rar-compressed application/octet-stream':
$type = "rar";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'image/gif':
$type = "gif";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'image/pjpeg':
$type = "pjpeg";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'image/jpeg':
$type = "jpeg";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'image/png':
$type = "png";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'image/jpg':
$type = "jpg";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'image/bmp':
$type = "bmp";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'imagesup'") or die(mysql_error());
break;
case 'text/java':
$type = "java";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
case 'text/plain':
$type = "txt";
$add = $settings->imagesup + 1;
mysql_query("UPDATE `settings` SET `value` = '$add' WHERE `name` = 'Files'") or die(mysql_error());
break;
}
//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_uploaded_file('filename') returns true if
//a file was uploaded via HTTP POST. Returns false otherwise.
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{//begin of is_uploaded_file
//Get the Size of the File
$size = $_FILES['filetoupload']['size'];
//Make sure that $size is less than 1MB (1000000 bytes)
if ($size > $size_bytes)
{
redirect('index.php?error=1');
exit();
}
//check file type
if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
{
redirect('index.php?error=2');
exit();
}
// $filename will hold the value of the file name submetted from the form.
$filename = $_FILES['filetoupload']['name'];
//Move the File to the Directory of your choice
//move_uploaded_file('filename','destination') Moves afile to a new location.
if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {
//tell the user that the file has been uploaded and make him alink too;).
$i = 1;
while($a < '915445101644545455') {
if(!file_exists('' . $upload_dir . '[' . $i . ']' . $filename . ''))
{
$newn = '[' . $i . ']' . $filename . '';
rename($upload_dir.$filename, $upload_dir.$newn);
$a = '915445101644545455';
}
else {
$a == '0';
$i++;
}
}
// MSQL
$newnn = $settings->nextname + 1;
mysql_query("UPDATE `settings` SET `value` = '$newnn' WHERe `name` = 'nextname'") or die(mysql_error());
redirect('index.php?error=4&newfile=' . $newn . '&viewname=' . $filename . '&c=true');
}
else
{
//Print error
redirect('index.php?error=3');
exit();
}
}
//end of is_uploaded_file
?>
Could anyone help me?
Cheers
