473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Get file upload extension

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
Jan 13 '08 #1
4 13722
MarkoKlacar
296 Expert 100+
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
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
Jan 14 '08 #2
Markus
6,050 Expert 4TB
[php]
$_FILES['file_upload']['type'];
[/php]
Is what you're after :)
Jan 14 '08 #3
[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
Jan 15 '08 #4
Markus
6,050 Expert 4TB
Have a look at this thread
Jan 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: jrefactors | last post by:
I have an upload file operation in the web application. UploadForm.jsp is the form, and UploadAction.jsp is the form processing. The web server is Websphere. //UploadForm.jsp <FORM...
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
2
by: Dan | last post by:
Hi, I know this code is not entirely javascript, but bare with me. Can you please tell me why this does not work: page: filemanager.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
3
by: Hamayun Khan | last post by:
I have Two asp pages addfiles.asp insert.asp addfiles.asp is used to browse the files which i want to upload to server. in IE both the pages run and the files uploads ok. There is...
10
by: jonathan184 | last post by:
Hi I am tryin to validate certian types of files to be uploaded and file size and if this follows this correctly then insert in db this is the code i did so far. So far I commented out the parts...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
4
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of...
4
by: Noorain | last post by:
Sir I want to CV(doc or pdf format) upload in database. Locally its script run my server but when i hosting it doesn't work. file doesn't upload. Its display, File format is wrong, please try...
24
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.