Ik vond mijn vorige post hieromtrend niet meer terug, daarom maar een
nieuwe.
Ik heb een scriptje in php geschreven om files mee te uploaden. Het werkt
wonderwel maar het enigste wat verkeerd loopt is dat als ik te grote
bestanden (limiet ligt op 5mb) probeer te uploaden dan krijg ik de melding
dat ik een verkeerd file-type probeer te uploaden terwijl ik eigenlijk de
melding wens te zien dat de file te groot is die geupload wordt. Kan iemand
mij uitleggen wat ik verkeerd heb gedaan? Andere opmerkingen ivm met het
script blijven welkom.
Mvg, Egwin
<?php
if(file_exists('../../private/open_db.inc') &&
is_readable('../../private/open_db.inc'))
include('../../private/open_db.inc');
$db = OpenDb() or die ("can not connect");
// Define some variables
$author = $_SESSION['user'];
$date = date("d/m/y");
$subject = $_POST['subject'];
$userfile = $_POST['userfile'];
$description = $_POST['description'];
$filetype = $_FILES['userfile']['type'];
$filename = $_FILES['userfile']['name'];
$filesize = $_FILES['userfile']['size'];
$uploadfile = $_FILES['userfile']['tmp_name'];
$uploaddir = "/opt/www/warniere/web/chemical.while.be/members/files/";
$filetype_array = array("application/pdf", "application/msword",
"application/vnd.ms-excel", "application/x-zip-compressed", "image/jpeg",
"image/gif", "image/png");
$upload_errors = array("<strong>$filename was uploaded
succesfully!</strong> You can upload another file if you like.",
"<strong>The file you are trying to upload is too big!</strong> Only files
less than 5 mb are allowed.",
"<strong>The file you are trying to upload is too big!</strong> Only
files less than 5 mb are allowed.", "<strong>The file was only partially
uploaded.</strong> Please try again", "<strong>You didn't select a file to
upload!</strong> Please select a file.<br />");
// Choose the directory were the file will be placed
switch($subject)
{
case 'IAP': $subject_dir = "IAP/";
break;
case 'UO2': $subject_dir = "UO2/";
break;
default: $subject_dir = "";
}
$file_destination = $uploaddir.$subject_dir.$filename;
$file_link =
"http://www.chemical.while.be/members/files/".$subject_dir.$filename;
// Put file
if(($subject == "0") || (!in_array($filetype,$filetype_array)) ||
is_file($file_destination))
{
echo 'It seems that there are some problems:<br />';
if($subject == "none"){
echo "<strong>You didn't choose a subject for the file!</strong> Please
choose one below.<br />";
}
if (!in_array($filetype,$filetype_array)){
echo "<strong>Invalid file type!</strong> Either you didn't select a file
or you tried uploading a file other than a PDF, Word or Excel document, JPEG
or GIF image file or Zip file.<br />";
}
if(is_file($file_destination)){
echo "<strong>The file you are trying to upload already exists in the
database.</strong> Please rename your file and try again.<br />";
}
include 'add_file_form.php'; // Show the form again!
return false;
}
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
move_uploaded_file($uploadfile, $file_destination);
// Add file info to database
$sql = "INSERT INTO chemical_files
(subject,filename,description,link,author,date) VALUES
('$subject','$filename','$description','$file_link ','$author','$date')";
$result = mysql_query($sql);
echo $upload_errors[$_FILES['userfile']['error']];
include 'add_file_form.php';
}
else
echo $upload_errors[$_FILES['userfile']['error']];
?>

Likes:

Quote