Alright,
I have been trying this for a while. I am trying to limit the uploaded files type, but when I upload the PHP file to the site and try to use it, and use a allowed file, it says it is not allowed. Any help? Any way heres my code…
Second Attempt (One im working with now):
<?php
$submitFile = $_POST['submitFile'];
if ($submitFile)
{
if ((($_FILES["file"]["type"] == "application/x-rar-compressed") // Rar Type Files
|| ($_FILES["file"]["type"] == "application/zip") // Zipped Folders
|| ($_FILES["file"]["type"] == "application/octet-stream")) // MySQL Files
&& ($_FILES["file"]["size"] < 209715200))
{
// File name and extensions
$filetmpname = $_FILES['file']['name']; // Name of oG file
$ext = substr($filetmpname, strpos($filetmpname,'.'), strlen($filetmpname)-1); // Ext
$filename = substr(md5(time().$i++), -6).$ext;
$target = $SETT['upload_dir'].$filename;
// Check the directory is writable
if (!is_writable($SETT['upload_dir']))
{
$ERROR = 'You cannot upload to the folder that was specified!';
}
else
{
// Create text such as title and desc
$title = mysql_escape_string(strip_tags(trim($_POST['title'])));
$desc = mysql_escape_string(strip_tags(trim($_POST['desc'])));
$author = "Guest";
$report = "0";
$dl_url = $CONF['url'].$SETT['upload_dir'].$filename;
if ($title&&$desc&&$dl_url)
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
mysql_query("INSERT INTO downloads VALUES ('', '$author', '$title', '$desc', '$report', '$dl_url')");
$gatherDownloadRecently = mysql_query("SELECT * FROM users WHERE username='$USERNAME'"); // Select the username table and our username
$numrows = mysql_num_rows($gatherDownloadRecently); // Gather the info
if ($numrows!=0) // Check if url exists
{
while ($row = mysql_fetch_assoc($gatherDownloadRecently)) // Gather our details
{
$dbUrl = $row['uniqueID']; // Collect DB ID
}
echo "<meta http-equiv='refresh' content='0; URL=".$CONF['url']."/file.php?id=".$dbUrl."'>";
}
else
{
$ERROR = "We couldnt find the file after it was uploaded?!";
}
}
else
{
$ERROR = 'There was an error uploading the file!';
}
}
else
{
$ERROR = "Please fill in all the fields before attempting to upload!";
}
}
}
else
{
$ERROR='The file is not the right type or it is too large!';
}
}
?>
First attempt:
<?php
$submitFile = $_POST['submitFile'];
if ($submitFile)
{
// Configuration - Options
$allowed_filetypes = array('.rar','.zip','.pdf','.sql','.xml','.gz');
$max_filesize = 209715200;
// File name and extensions
$filetmpname = $_FILES['file']['name']; // Name of oG file
$ext = substr($filetmpname, strpos($filetmpname,'.'), strlen($filetmpname)-1); // Ext
$filename = substr(md5(time().$i++), -6).$ext;
$target = $SETT['upload_dir'].$filename;
// Check the filetype is allowed
if(!in_array($ext,$allowed_filetypes))
{
$ERROR = "The type of file you uploaded is not allowed!<br />".$ext;
}
else
{
// Check the filesize
if (filesize($_FILES['file']['tmp_name']) > $max_filesize)
{
$ERROR = "The file you uploaded is too large!";
}
else
{
// Check the directory is writable
if (!is_writable($SETT['upload_dir']))
{
$ERROR = 'You cannot upload to the folder that was specified!';
}
else
{
// Create text such as title and desc
$title = mysql_escape_string(strip_tags(trim($_POST['title'])));
$desc = mysql_escape_string(strip_tags(trim($_POST['desc'])));
$author = "Guest";
$report = "0";
$dl_url = $CONF['url'].$SETT['upload_dir'].$filename;
if ($title&&$desc&&$dl_url)
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
mysql_query("INSERT INTO downloads VALUES ('', '$author', '$title', '$desc', '$report', '$dl_url')");
$gatherDownloadRecently = mysql_query("SELECT * FROM users WHERE username='$USERNAME'"); // Select the username table and our username
$numrows = mysql_num_rows($gatherDownloadRecently); // Gather the info
if ($numrows!=0) // Check if url exists
{
while ($row = mysql_fetch_assoc($gatherDownloadRecently)) // Gather our details
{
$dbUrl = $row['uniqueID']; // Collect DB ID
}
echo "<meta http-equiv='refresh' content='0; URL=".$CONF['url']."/file.php?id=".$dbUrl."'>";
}
else
{
$ERROR = "We couldnt find the file after it was uploaded?!";
}
}
else
{
$ERROR = 'There was an error uploading the file!';
}
}
else
{
$ERROR = "Please fill in all the fields before attempting to upload!";
}
}
}
}
}
?>