PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 23rd, 2005, 04:28 PM
confirm045 confirm045 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 28 confirm045 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 54 sec
Reputation Power: 0
how do you restrict the types of files being uploaded?

How do you restrict files so that you can upload only doc files?

Reply With Quote
  #2  
Old January 24th, 2005, 06:18 AM
CBauman CBauman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 CBauman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<?php
$split = explode(".", $_FILES['file_to_upload']['name']);

$extension = strtolower($split[count($split) - 1]);

if ($extension == "doc")

{

// upload file

}
?>

Reply With Quote
  #3  
Old January 24th, 2005, 12:35 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 5
A more foolproof way would be to check the file type from the $_FILES array:

PHP Code:
if($_FILES['type'] != 'application/msword')
 {
   echo 
'Incorrect file type';
 } 

Reply With Quote
  #4  
Old January 25th, 2005, 09:13 PM
confirm045 confirm045 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 28 confirm045 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 54 sec
Reputation Power: 0
What if i had the following code, how am i suppose to restrict the file chosen? ive tried both of the above methods and it doesnt seen to work properly.


if($File) // if file exists

{

print "File Name: <strong> $File_name </strong> <p>\n"; // name of file
print "File size: <strong> $File_size bytes </strong> <p>\n"; // size of file in bytes

if (copy($File, "c:\\$File_name"))
{
print "File successfully uploaded! <p>\n";
}
else
{
print "Unable to upload file <p>\n";
}
unlink ($File); // deletes the file

}

Reply With Quote
  #5  
Old January 26th, 2005, 01:44 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 5
Where are $File and $File_name being set? And what version of PHP are you using?

Reply With Quote
  #6  
Old January 26th, 2005, 07:05 PM
confirm045 confirm045 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 28 confirm045 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 54 sec
Reputation Power: 0
it's set to the same php as the file upload form. Im using Phptriad 2.1.1. The php script points to itself when the file is uploaded.

Reply With Quote
  #7  
Old January 27th, 2005, 09:46 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Does the basic file upload work?
Are you suing PHP's variables $_FILES anywhere?

May I refer you to Jonathan Wichmann's article Creating a multifile upload script in PHP?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > how do you restrict the types of files being uploaded?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT