PHP上传14MB文件失败(PHP upload 14MB file failing)

编程入门 行业动态 更新时间:2024-10-11 19:18:31
PHP上传14MB文件失败(PHP upload 14MB file failing)

我试图弄清楚为什么这个上传脚本失败。

从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>

这是PHP脚本:

<?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"; } } ?>

请原谅嵌套的IF语句。 我在youtube上发布了这个视频: https : //www.youtube.com/watch?v = PRCobMXhnyw

上面的代码有效。 我可以上传文件,当发生错误时,我收到相应的错误消息。

但是,我遇到了一个无法上传的文件。 这是一个允许的文件,一个word文档,恰好是14MB。 不确定这是否太大了。 但即使如此,我试图上传的文件太大也无法通过file_size检查,我会收到相应的错误消息。

在这种情况下,我得到的只是一个空白屏幕。 我可以在初始IF语句之前和之后回应'hello',但它在第一个IF后立即失败。

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.

最满意答案

您应该在php.ini文件中增加upload_max_filesize的值(默认情况下为2M )(其位置取决于您的操作系统),然后重新启动Web服务器。

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.

更多推荐

file,upload,IF,电脑培训,计算机培训,IT培训"/> <meta name="description&qu

本文发布于:2023-08-04 01:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1407703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   文件   PHP   MB   failing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!