Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1202 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

$_files

Thread title: $_files
Closed Thread    
    Thread tools Search this thread Display Modes  
10-10-2005, 10:10 AM
#1
ktsirig is offline ktsirig
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 46
iTrader: 0 / 0%
 

ktsirig is on a distinguished road

  Old  $_files

Hi all!

I have a question: I am constructing a form where the user can upload a file.
I need however to verify that the file uploaded is a TEXT file.

Is $_FILE['userfile']['type'] what I need? I am asking this because no matter if I upload a .txt or a .gif file, PHP says they are both $_FILE['userfile']['type']='text' and so, they are both uploaded on the server, whereas there should be only .txt file uploaded and not the .gif file.

In general, how can I allow only text files to be uploaded?
(Of course, i can't rely much on the extension I believe)..

Thanx

10-10-2005, 11:25 AM
#2
Jonny is offline Jonny
Status: Member
Join date: Feb 2005
Location: UK
Expertise:
Software:
 
Posts: 335
iTrader: 0 / 0%
 

Jonny is on a distinguished road

  Old

You can't really do much else other than judging by the extension.

The best you could probably do is remove all illegal characters from it and just serve it as text.

10-10-2005, 12:46 PM
#3
xZaft is offline xZaft
Status: Member
Join date: Jul 2005
Location: Massachusetts, US
Expertise:
Software:
 
Posts: 428
iTrader: 0 / 0%
 

xZaft is on a distinguished road

  Old

Yeah, checking the extension is the only way. Those weird characters (ASCII, Symbols?) can be put into a text file. So like no longer than 10000 lines?

10-10-2005, 01:16 PM
#4
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

You could rely on the file's extension for some soft protection. Obviously that wouldn't stop people uploading an image (or any other type) file with a .txt extension. However, if you force the server (using .htaccess or some such device) to only output plain text from the folder(s) where the files are being stored then their uploading any other type of file than plain text would be pointless.

10-10-2005, 04:03 PM
#5
ktsirig is offline ktsirig
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 46
iTrader: 0 / 0%
 

ktsirig is on a distinguished road

  Old

thanx to all for your time,

I use :

if ($_FILES['userfile']['type']='text/plain')
{then OK}

else
{wrong file type}

but it doesn't seem to work. PHP uploads both text files and .exe files.
Any thoughts?

10-10-2005, 06:04 PM
#6
opserty is offline opserty
Status: I love this place
Join date: Jan 2005
Location: UK, Birmingham
Expertise:
Software:
 
Posts: 606
iTrader: 0 / 0%
 

opserty is on a distinguished road

Send a message via MSN to opserty

  Old

you should be using == for comparision, = is used for assigning. You cannot assign in if functions

10-12-2005, 10:20 PM
#7
Cborrow is offline Cborrow
Status: I'm new around here
Join date: Aug 2005
Location: Flint, MI
Expertise:
Software:
 
Posts: 7
iTrader: 0 / 0%
 

Cborrow is on a distinguished road

Send a message via AIM to Cborrow

  Old

You could try this

PHP Code:
$file substr($_FILES['userfile']['name'], -3);

if(
$file != "txt") {
echo 
"Invaild file type"; exit;
}
else {
//Do whatever is needed to be done

10-18-2005, 12:28 PM
#8
ktsirig is offline ktsirig
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 46
iTrader: 0 / 0%
 

ktsirig is on a distinguished road

  Old

Thanx a lot guys!

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed