For some reason when i upload files, it goes through my script after submitted, then even if I leave the title text field blank, it still uploads. Here’s my code:
[php]
<?php
if($_SESSION["id"] == $userid && isset($_SESSION["login"]))
{
if (isset($_POST["uploadsubmit"]))
{
if ($_FILES["upload"]["name"] == "")
{
$_SESSION["upload"] = "Please choose a file to upload";
$_SESSION["uploadsuccess"] = "";
$_SESSION["uploadsize"] = "";
}
if ($_FILES["upload"]["name"] != "")
{
$_SESSION["upload"] = "";
}
if ($_FILES["upload"]["type"] == "image/gif")
{
$_SESSION["upload"] = "Filetype not supported";
}
if ($_FILES["upload"]["size"] > 10000000)
{
$_SESSION["uploadsize"] = "File size is too big";
$_SESSION["upload"] = "";
$_SESSION["uploadsuccess"] = "";
}
if (empty($_POST["title"]) || strlen($_POST["title"]) > 50)
{
$_SESSION["title"] = "Please enter a title for your uploaded file";
}
if (!empty($_POST["title"]) && strlen($_POST["title"]) < 50)
{
$_SESSION["title"] = "";
}
if (empty($_POST["describe"]) || strlen($_POST["describe"]) < 10 || strlen($_POST["describe"]) > 200)
{
$_SESSION["describe"] = "Please give your uploaded file a description (Must be between 10-200 characters)";
}
if (!empty($_POST["describe"]) && strlen($_POST["describe"]) > 10 And strlen($_POST["describe"]) < 200)
{
$_SESSION["describe"] = "";
}
if ($_POST["category"] == "SELECT A CATEGORY")
{
$_SESSION["category"] = "Please select the category you wish your uploaded file to feature in";
}
if ($_POST["category"] != "SELECT A CATEGORY")
{
$_SESSION["category"] = "";
}
if ($_FILES["upload"]["name"] != "" && $_FILES["upload"]["size"] < 10000000 && $_SESSION["describe"] == "" && $_SESSION["category"] == "" && $_SESSION["title"] == "" && $_FILES["upload"]["type"] ==
"image/jpeg" || $_FILES["upload"]["type"] == "image/png" || $_FILES["upload"]["type"] == "image/pjpeg" || $_FILES["upload"]["type"] == "audio/mpeg")
{
$name = $_FILES["upload"]["name"];
$type = $_FILES["upload"]["type"];
$file_name = $_FILES['upload']['name'];
$random_digit = rand(0000,200000);
$new_file_name = $random_digit . $file_name;
$directory = $new_file_name;
$path = "uploads/" . $new_file_name;
if (copy($_FILES['upload']['tmp_name'], $path))
{
require "chapterpdo4.php";
}
}
}
?>
Select a File:
<?php echo $_SESSION["upload"]; echo $_SESSION["uploadsize"]; ?>
<?php echo $_SESSION["uploadsuccess"]; ?>
Title: <?php echo $_SESSION["title"]; ?>
Description:
<?php echo $_SESSION["describe"]; ?>
Category:
SELECT A CATEGORY Singing
Dancing
Modeling
Programming/Development
Art
Acting
Music/Songwriting
Comedy
Rapping
Tricks
<?php echo $_SESSION["category"]; ?>
<?php
}
?>
[/php]
I only allow the file to upload while there are no session errors. but even though the session errors are active, it still submits and returns true even though i leave the fields blank. what is wrong with this code? thanks so much