Connecting Tech Pros Worldwide Forums | Help | Site Map

Get file upload extension

Newbie
 
Join Date: Jan 2008
Posts: 5
#1: Jan 13 '08
Hi all

Can anyone please tell me the best way to get the whether an uploaded file is a csv file and also to check if the uploaded file has more than 1 column. i have tried to get filetype but am unable to get it working and have no idea on how to count number of columns in csv file, any help would be appreciated.

[PHP]
$filename = basename($_FILES['file_upload']['name']);
//echo $filename;

//$filetype = $_FILES['file_upload']['type'];

//if($filetype != '.csv')
//$error["fileext"] = "Please upload a .csv file";

if(empty($filename))
$error["filename"] = "The name of the file was not found.";

if(empty($error))
{
$newfile = "/tmp/" . $filename;
//echo $newfile;
$result = @move_uploaded_file($_FILES['file_upload']['tmp_name'], $newfile);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";

}
[/PHP]



Regards Brad

MarkoKlacar's Avatar
Expert
 
Join Date: Aug 2007
Location: Stockholm, Sweden
Posts: 294
#2: Jan 14 '08

re: Get file upload extension


Hi Brad,

I don't quite see the code where you're trying to get the file extension.
Can you post that part of the code?

Cheers
Quote:

Originally Posted by Unnamed

Hi all

Can anyone please tell me the best way to get the whether an uploaded file is a csv file and also to check if the uploaded file has more than 1 column. i have tried to get filetype but am unable to get it working and have no idea on how to count number of columns in csv file, any help would be appreciated.

[PHP]
$filename = basename($_FILES['file_upload']['name']);
//echo $filename;

//$filetype = $_FILES['file_upload']['type'];

//if($filetype != '.csv')
//$error["fileext"] = "Please upload a .csv file";

if(empty($filename))
$error["filename"] = "The name of the file was not found.";

if(empty($error))
{
$newfile = "/tmp/" . $filename;
//echo $newfile;
$result = @move_uploaded_file($_FILES['file_upload']['tmp_name'], $newfile);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";

}
[/PHP]



Regards Brad

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#3: Jan 14 '08

re: Get file upload extension


[php]
$_FILES['file_upload']['type'];
[/php]
Is what you're after :)
Newbie
 
Join Date: Jan 2008
Posts: 5
#4: Jan 15 '08

re: Get file upload extension


Quote:

Originally Posted by markusn00b

[php]
$_FILES['file_upload']['type'];
[/php]
Is what you're after :)


Thats what i originially tried but as you can see i commented it out when i could not get it to work, for some reason that command only distinguishes whether it is an excel file or not and will not return the file extension

any ideas on how to fix this would be very much appreciated.

Regards Brad
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#5: Jan 16 '08

re: Get file upload extension


Have a look at this thread
Reply