Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Uploading CSV file to server with PHP help please...
Old 02-03-2008, 08:43 AM Uploading CSV file to server with PHP help please...
Hank Scorpio's Avatar
Novice Talker

Posts: 11
Name: Hank Scorpio
Trades: 0
Hello All

Could anybody give me any idea's on a problem I am having. I have been on the W3 schools excellent site and used their PHP upload script, found at the link below.

http://www.w3schools.com/php/php_file_upload.asp

This works great except for one small problem. I don't want to upload image files' I want to upload a CSV file to the server. From there I want to import it into MySql, which I have written a script for and it is working fine.

However, trying to upload a CSV file returns the message "File Invalid". Any idea's on what is required to allow CSV uploads?

Just to give you some background, this is for a project at work, we have been told there is no chance of IT doing it, but the senior management are happy for us to "dabble" and see what we can come up. It will be hosted externally, but entered through a Login system. It will basically be a CSV file of stock info loaded into the database (the CSV is sent to us on email by a 3rd party company), we will upload the CSV to the server, and then import into the database on the server. We then have numerous PHP script's with various query's for different info req'd to streamline our operation.

Any help anyone could give me would be great, thanks for taking your time to read this.

HS
Hank Scorpio is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-03-2008, 09:33 AM Re: Uploading CSV file to server with PHP help please...
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Looking at the upload script only three mime types are allowed.

You will need to add a further mime type for csv files. Add this line between jpeg and pjpeg.
PHP Code:
 || ($_FILES["file"]["type"] == "application/octet-stream"
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 02-03-2008, 02:19 PM Re: Uploading CSV file to server with PHP help please...
Hank Scorpio's Avatar
Novice Talker

Posts: 11
Name: Hank Scorpio
Trades: 0
Hi Maxximus

Thanks for the reply, I had seen something like that when I googled it, but I have tried it and it doesn't seem to work, it still say's invalid file.

At the moment I am testing it locally using Apache.

Perhap's I need to check my PHP.ini or even something on Apache.
Hank Scorpio is offline
Reply With Quote
View Public Profile
 
Old 02-03-2008, 02:44 PM Re: Uploading CSV file to server with PHP help please...
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Think the problem is there is no formal specification for .csv files. Various programs can produce different mime types.

When i tested with a local csv file I got 'application/octet stream'. The easiest way is to test is to add the line

PHP Code:
  echo "file type is ".$_FILES["file"]["type"]; 
at the top of the upload script and see what mime type is shown when you try to upload your csv file.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 02-04-2008, 01:01 AM Re: Uploading CSV file to server with PHP help please...
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
"trying to upload a CSV file returns the message "File Invalid" sounds like a nonsense. Who exactly returns this message? Your function that copies the uploaded file? Your function that tries to read it? For the php's file upload mechanism csv file does not differ at all from the image file or text file or anything else.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Uploading CSV file to server with PHP help please...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.06279 seconds with 12 queries