0

I'm currently using code that uploads a CSV file but I am using the PATHINFO_EXTENSION to prevent any other file types being submitted (file types other than .csv)

This is the code (with html):

http://pastebin.com/m8eNXAgE

I have the following problem:

==> I initially used $file = $_FILES['csv']['tmp_name']; but the basename came up randomly and the extension was a .tmp even thought the file I uploaded was a .csv I then changed it to $file = $_FILES['csv']['name']; but I got the following error:

Warning: fopen(computing.csv): failed to open stream: No such file or directory in ... Warning: fgetcsv() expects parameter 1 to be resource, boolean given in ...

Please can anyone explain and help what the problem is with the code and I have been searching for a while and cant seem to find a solution.

Any help is appreciated, thanks.

  • you can use `var_dump($_FILES)` for check you file array. and I fink `$_FILES['file']` because you input name file `
    ` and post code in question
    – Naumov Mar 12 '16 at 22:52

1 Answers1

0

You should actually use $_FILES['csv']['tmp_name']. This is the name that PHP allocated on the server for the uploaded file. You can read more here: http://php.net/manual/en/features.file-upload.php

obe
  • 7,378
  • 5
  • 31
  • 40
  • When I use $_FILES['csv']['tmp_name'] I only get a random filename and a .tmp extension rather the filename and the extension of the original file. I want to check the extension of the original file to make sure its a .csv – Redrooster46 Mar 13 '16 at 13:41
  • You should use "name" if you want to verify that the uploaded file had a "csv" extension, but when you want to actually access the file on disk you need to access it via "tmp_name" because that's where it's stored (at least until you copy it elsewhere)... – obe Mar 13 '16 at 18:43