473,396 Members | 1,766 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,396 software developers and data experts.

Cannot upload .csv using text/plain

I am using Excel to save a spreadsheet in .csv format. This creates a
text file with extension .csv
But when I try to upload the file to the server by checking for its
MIME type using $_FILE['userfile']['type'] I get my own error message
that the file is not text file. If I change the extension to .txt I am
able to upload the file.
This is not reliable as it is only relying on extensions rather than
contents of the file. Is there a reliable way of checking for file
formats. I would like to upload jpeg, gif and text files reliably.

Thank you
John
Jul 17 '05 #1
2 3356
John wrote:

I am using Excel to save a spreadsheet in .csv format. This creates a
text file with extension .csv
But when I try to upload the file to the server by checking for its
MIME type using $_FILE['userfile']['type'] I get my own error message
that the file is not text file. If I change the extension to .txt I am
able to upload the file.
This is not reliable as it is only relying on extensions rather than
contents of the file. Is there a reliable way of checking for file
formats. I would like to upload jpeg, gif and text files reliably.


For gif and jpeg, you can use getimagesize() (the 3rd or 4th array element, I
think). Not sure how you'd go about validating a CSV though.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2
John wrote:
I am using Excel to save a spreadsheet in .csv format. This creates a
text file with extension .csv
But when I try to upload the file to the server by checking for its
MIME type using $_FILE['userfile']['type']
I trust you meant $_FILES.
I get my own error message that the file is not text file.
The value of $_FILES['userfile']['type'] is whatever the file's media
type was deemed to be at the client-side, if such deeming took place
at all; as the Content-Type header is optional in multipart types
(and data sets of "file upload forms" ought to be sent using
multipart/form-data), a file's media type may be absent from the
request -- you couldn't, then, figure out the file's media type from
$_FILES. Morever, if a browser tries but is unable to determine an
appropriate media type, it should fall back on the oft-misused
application/octet-stream type (RFC2388, sec. 3), i.e., labelled the
entity body "arbitrary binary data" (RFC2046, sec. 4.5.1).

Internet Explorer 6.0, for example, sends a Content-Type value of
application/octet-stream with CSV files, which is fine; Opera 7.10
sends text/comma-separated-values, which is curious since that media
type isn't registered. There is, in fact, no registered media type
for CSV files. Many transactions are conducted with text/x-csv or
other private subtypes.

I wonder how a TSV (Tab Separated Values, media type text/tab-
separated-values) file would bear up.
If I change the extension to .txt I am able to upload the file. This
is not reliable as it is only relying on extensions rather than
contents of the file.
There is no normative source limiting the determining of files' media
types from filename extensions. Manifold heuristics may be employed.
Is there a reliable way of checking for file formats.
Not "bullet proof",

http://www.php.net/manual/en/ref.mime-magic.php
http://www.php.net/manual/en/functio...ntent-type.php
I would like to upload jpeg, gif and text files reliably.


Shawn's already proposed getimagesize for JPEGs and GIFs.

http://www.php.net/manual/en/function.getimagesize.php

--
Jock
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Muppy | last post by:
I've created a page with a form to upload files: <h1>Upload di un file</h1> <form enctype="multipart/form-data" method="post" action="do_upload1.php"> <p><strong>File da trasferire:</strong><br>...
3
by: Amy Kimber | last post by:
Hello, I have a file upload page, and I've had it working fine, it was beautiful :-) Anyway, the powers that be moved hosts... and it doesn't work now. The file name is correct, the directory...
5
by: Ariel Dolan | last post by:
Can I use HtmlInputFile to only get the selected file name but not actually upload the file? Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: Mike Kelly | last post by:
Hi. I've built a page using standard ASP.NET 2.0 features and when I upload a large file (>20MB) to our intranet server, I get a paltry 100KB/s on our 100Mb/s LAN. Simply copying the file, I get...
4
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image...
1
by: Gert Conradie | last post by:
The following code can uplaod text files. When i upload a binary file it fail. I might be: 1) using the wrong Encoding 2) will have to System.Convert.ToBase64String the content of the binary...
18
jhardman
by: jhardman | last post by:
Have you ever wanted to upload files through a form and thought, "I'd really like to use ASP, it surely has that capability, but the tutorial I used to learn ASP didn't mention how to do this."? ...
12
by: GuangXiN | last post by:
I want the file upload element disappear, instead of it, I place a text box and a button with my own css defination. but it doesn't work on IE7. What should I do now? <form action="upload.php"...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.