twigg
twigg

Reputation: 3993

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

I'm uploading a .PDF and .ZIP file via a HTML form then passing it to my PHP script where the file is moved from the temp folder and placed in a specified folder. Now this works great on files under 2mb, anything over I will get the following error message:

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

The filename isn't empty and the code works fine for files under 2mb in size.

I checked my php.ini file in /etc/ folder (im running centos6.4) and in its config I have

 upload_max_filesize = 50M

I'm thinking this is still a PHP config issue thats causing the error on files over 2mb, is there any other config I need to be looking at?

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

UPDATE

Ok I have been doing a bit of testing, the $_FILES array seems to be empty when the filesize is over 2MB, under 2MB the array returns the name, type, tmp_name, error, size as expected.

What would the reason be the $_FILES is empty with files over 2MB. Yes my upload_max_filesize is set higher than the file size and my post_max_size is set higher than my upload_max_filesize. Yes I have restarted Apache after making changes to the php.ini file

Upvotes: 0

Views: 6452

Answers (1)

claustrofob
claustrofob

Reputation: 4984

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

Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.

Upvotes: 5

Related Questions