Rosamunda
Rosamunda

Reputation: 14990

How to find out the error when a csv file won't be uploaded by php?

I'm creating csv files and uploading them into my PHP application.

I create every file the same way, and just change the content every time. I do this in order to import information manually from one site to another.

My problem is that one csv file is not read properly.

What I've done with the attachment field in the form is putting it into a variable and var_dump the variable:

$adjunto = $_FILES['adjunto'];
var_dump($adjunto);

And here's the result:

array(5) {
  ["name"]=>
  string(20) "importArticulos1"
  ["type"]=>
  string(0) ""
  ["tmp_name"]=>
  string(0) ""
  ["error"]=>
  int(1)
  ["size"]=>
  int(0)
}

Other files do upload without issues:

array(5) { when 
  ["name"]=>
  string(11) "importJuris"
  ["type"]=>
  string(24) "application/octet-stream"
  ["tmp_name"]=>
  string(14) "/tmp/phpzC2FAM"
  ["error"]=>
  int(0)
  ["size"]=>
  int(1881617)
}

My question is: How can I know more about the error when a file is simply not read or not recognized?

By the way, the error log tells me this:

[18-Aug-2019 08:23:20 America/Argentina/Buenos_Aires] PHP Warning: fopen(/home/rosamunda/public_html/importar.csv): failed to open stream: No such file or directory in /home/rosamunda/public_html/demo1.php on line 131

The line 131 tries to open the file with fopen() which won't open because the file is not even recognized.

Upvotes: 0

Views: 499

Answers (1)

Mark Hamstra
Mark Hamstra

Reputation: 722

For the failed upload, the provided error number is 1. Looking at the official list of error codes, error number 1 is:

UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

So you'll need to increase the upload_max_filesize option in your php.ini.

Upvotes: 2

Related Questions