0

我正在通过 HTML 表单上传 .PDF 和 .ZIP 文件,然后将其传递给我的 PHP 脚本,在该脚本中,文件从临时文件夹中移动并放置在指定的文件夹中。现在这对 2mb 以下的文件非常有效,任何超过我都会收到以下错误消息:

Warning: copy() [function.copy]: Filename cannot be empty

文件名不为空,代码适用于 2mb 以下的文件。

我在 /etc/ 文件夹中检查了我的 php.ini 文件(我正在运行 centos6.4),并且在它的配置中我有

 upload_max_filesize = 50M

我认为这仍然是一个 PHP 配置问题,导致超过 2mb 的文件出现错误,我还需要查看其他配置吗?

<?php
session_start();
$ref = $_POST['doc_ref'];
$rev = $_POST['doc_rev'];
$owner = $_POST['doc_owner'];
$contract = $_POST['contract'];
$cat = $_POST['cat'];
$type = $_POST['type'];
$pdf = $_FILES['pdf'];
$zip = $_FILES['zip'];
$pdf_name = $_FILES['pdf']['name'];
$content = $_POST['doc_content'];
$userid = $_SESSION['users_id'];
date_default_timezone_set('UTC');
$date = date_create();

// get the pdf from the form then remove the extension
$title = $_FILES["pdf"]["name"];
$title = pathinfo($title,PATHINFO_FILENAME);


$sth = "SELECT * FROM `contracts` WHERE `contracts_id`='$contract'";
$result = $conn->query($sth);   
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
    $contract_name = $row['contracts_name'];
    $contract_prefix = $row['prefix'];
}

if ($contract_prefix)
{
    if ($type === '1')
    {
    $zippath = "zips/" . $contract_prefix . "/" . $contract_name . "/Forms/";
    $arcpath = "arc/" . $contract_prefix . "/" . $contract_name . "/Forms/";
    $pdfpath = "pdfs/" . $contract_prefix . "/" . $contract_name . "/Forms/";
    }elseif ($type === '2')
    {
    $zippath = "zips/" . $contract_prefix . "/" . $contract_name . "/Work Instructions And Process Flows/";
    $arcpath = "arc/" . $contract_prefix . "/" . $contract_name . "/Work Instructions And Process Flows/";
    $pdfpath = "pdfs/" . $contract_prefix . "/" . $contract_name . "/Work Instructions And Process Flows/";
    }
}else
{
    if ($type === '1')
    {
    $zippath = "zips/" . $contract_name . "/Forms/";
    $arcpath = "arc/" . $contract_name . "/Forms/";
    $pdfpath = "pdfs/" . $contract_name . "/Forms/";
    }elseif ($type === '2')
    {
    $zippath = "zips/" . $contract_name . "/Work Instructions And Process Flows/";
    $arcpath = "arc/" . $contract_name . "/Work Instructions And Process Flows/";
    $pdfpath = "pdfs/" . $contract_name . "/Work Instructions And Process Flows/";
    }
}

$pdfpath = $pdfpath . $_FILES["pdf"]["name"];
$zippath = $zippath . $_FILES["zip"]["name"];
// create archpath to store for later use
$arcpathfinal = $arcpath;
// append the current revision to the start of the zip files name for the arc
$arcpath = $arcpath . "Revision " . $rev . " - " . $_FILES["zip"]["name"];

//check the uploaded file is in PDF format and then move to correct directory
$allowed =  array('pdf');
$pdf = $_FILES['pdf']['name'];
$ext = pathinfo($pdf, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
    echo 'The file type must be a PDF!';
}else
{
    // move zip and pdf into correct folders
    move_uploaded_file($_FILES["pdf"]["tmp_name"], $pdfpath);
    move_uploaded_file($_FILES["zip"]["tmp_name"], $zippath);
}

// make a copy of zip file into arc folder
copy($zippath, $arcpath);

//INSERTING INTO DATABASE CODE HERE

更新

好的,我一直在做一些测试,当文件大小超过 2MB 时,$_FILES 数组似乎为空,在 2MB 下,数组按预期返回名称、类型、tmp_name、错误、大小。

$_FILES 文件超过 2MB 的原因是什么?是的,我的upload_max_filesize 设置为高于文件大小,而我的post_max_size 设置为高于我的upload_max_filesize。是的,我在更改 php.ini 文件后重新启动了 Apache

4

1 回答 1

5

http://www.php.net/manual/en/ini.core.php#ini.post-max-size

设置允许的帖子数据的最大大小。此设置也会影响文件上传。要上传大文件,该值必须大于upload_max_filesize。

于 2013-06-21T13:10:15.873 回答