I am using the following php file upload script to upload a file, create a folder directory and store the file in a folder then log the details of that file in my database.
My problem is that this works on one of my PDF documents aroun 54kb but when I try and upload a larger pdf around 5mb it says invalid file type. also I am having trouble uploading document file types in general. I don't know if this is because documents can be either docx or doc, but my script should support both types if possible.
Can someone please show me where I am going wrong? Thanks,
<?php
session_start();
include("config.php");
$supplier_name = $_POST['supplier_name'];
$supplier_number = $_POST['supplier_number'];
$start_date = date('Y-m-d', strtotime($_POST['start_date']));
$end_date = date('Y-m-d', strtotime($_POST['end_date']));
$notice = $_POST['notice'];
$steak = $_POST['steak'];
$supplier_name = stripslashes($supplier_name);
$supplier_name = mysql_real_escape_string($supplier_name);
$supplier_number = stripslashes($supplier_number);
$supplier_number = mysql_real_escape_string($supplier_number);
$start_date = stripslashes($start_date);
$start_date = mysql_real_escape_string($start_date);
$end_date = stripslashes($end_date);
$end_date = mysql_real_escape_string($end_date);
$notice = stripslashes($notice);
$notice = mysql_real_escape_string($notice);
$steak = stripslashes($steak);
$steak = mysql_real_escape_string($steak);
$rand = "HC" . substr(md5(microtime()),rand(0,26),5);
mkdir("../data/contracts/$rand");
$allowedExts = array("pdf", "doc");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/doc")
&& ($_FILES["file"]["size"] < 10000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 10000) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("../data/contracts/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../data/contracts/$rand/" . $_FILES["file"]["name"]);
$sql = "INSERT INTO supplier_contracts (id, supplier_name, supplier_number, contract_number, contract_start, contract_end, contract_termination_period, date, owner, steak_holder) VALUES ('', '$supplier_name', '$supplier_number','$rand', '$start_date', '$end_date', '$notice', now(), '{$_SESSION['user']}', '$steak')";
$result2 = mysql_query($sql);
if($result2) {
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">✖</div><h23>Thank You!</h23><p>Your Contract was successfully created. Your Contract number is: '.$rand.'.</p></div>';
header('Location: ' . $_SERVER['HTTP_REFERER']);
}else{
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">✖</div><h23>Oooops!</h23><p>There was an error trying to create this Contract. Please try again later.</p></div>';
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
} } }else{
$_SESSION['message2'] = '<div id="message_box2"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">✖</div><h23>Oooops!</h23><p>There was an error trying to create this Contract. Please try again later.</p></div>';
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>
php.iniis in the same folder of your php file? Oh, and to accept docx, per example, you need to change your$allowedExtsvar too.