我正在通过HTML表单上传.PDF和.ZIP文件,然后将其传递给我的PHP脚本,其中文件从temp文件夹移动并放在指定的文件夹中。现在这适用于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,错误,大小与预期一致。
如果文件超过2MB,$ _FILES是空的,原因是什么?是的,我的upload_max_filesize设置为高于文件大小,我的post_max_size设置为高于我的upload_max_filesize。是的,我在更改php.ini文件后重新启动了Apache
答案 0 :(得分:5)
http://www.php.net/manual/en/ini.core.php#ini.post-max-size
设置允许的帖子数据的最大大小。此设置也会影响文件上载。要上传大文件,此值必须大于upload_max_filesize。