Reputation: 3075
I am trying to figure out why this upload script is failing.
Starting with the HTML FORM:
<form role="form" action="api/upload.php" method="post" enctype="multipart/form-data">
<input id="file" name="file" type="file" />
<input class="btn btn-primary" type="submit" value="Upload" />
</form>
Here is the PHP script:
<?php
if(isset($_FILES['file'])){
$file = $_FILES['file'];
$target_file = basename($_FILES["file"]["name"]);
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$file_ext = explode('.',$file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('txt', 'jpg', 'xlsx', 'pptx', 'docx', 'doc', 'xls', 'pdf');
if(in_array($file_ext, $allowed)){
if($file_error === 0){
if($file_size <= 99600000){ // this was set to 600000
$file_name_new = uniqid('', true) . '.' . $file_ext;
$file_destination = '../files/' . $file_name;
if(move_uploaded_file($file_tmp, $file_destination)){
header("Location: ../index.php");
die();
}
else{
echo "There was a problem uploading the file";
}
}
else{
echo "The file is too large";
}
}
else{
echo "There was an error uploading the file";
}
}
else{
echo "The file type is not allowed";
}
}
?>
Please forgive the nested IF statement. I was going off of this video on youtube: https://www.youtube.com/watch?v=PRCobMXhnyw
The code above works. I can upload the files, and when an error occurs, I get the appropriate error message.
However, I have come across a file that will not upload. It is an allowed file, a word document, that happens to be 14MB. Not sure if that's too large. But even still, files that I tried to upload that were too large wouldn't get past the file_size check, and I would get the corresponding error message.
In this case, all I get is a blank screen. I can echo 'hello' before and after the initial IF statement, but it fails right after the first IF.
Upvotes: 3
Views: 281
Reputation: 5201
You should simply increase the value of upload_max_filesize
(by default it's 2M
) in your php.ini
file (its location depends on your operating system), and restart your web server.
Upvotes: 5