PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 10th, 2002, 03:48 AM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
File Upload / File type

I am writing a file upload script. before I write the file I only want to write it if it is a jpg.

So I wrote this line

$check_extention = explode(".", $image_upload_name);

if I echo ($check_extention[1] it shows jpg. now in the following line it does not work.

if ($check_extention[1] == "jpg") { $write_image = "ok"; }

Now if I echo $write_image it is empty. so it does not write as I directed it to do. Any clue to what I am doing wrong.

Reply With Quote
  #2  
Old August 10th, 2002, 04:19 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: File Upload / File type

well because you only want one file type, no need for explode function me thinks...try this:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $string_extension = ".jpg"; //sets your extension
  4. if($string_extension == '.jpg')
  5. {
  6.     $write_image = "ok";
  7. }
  8. ?>

not tested yet, but looks simple enough

Reply With Quote
  #3  
Old August 10th, 2002, 04:29 AM
siteworkspro.com siteworkspro.com is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 92 siteworkspro.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to siteworkspro.com Send a message via AIM to siteworkspro.com
RE: File Upload / File type

why done you just use this??/

if($image_upload_type != "image/jpeg")
//dont upload!

Reply With Quote
  #4  
Old August 10th, 2002, 12:12 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: RE: File Upload / File type

I'm taking it a little bit futher:

php Code:
Original - php Code
  1.  
  2. <?php
  3. function validateType($file_data_type)
  4. {
  5.     $acceptedFileTypes = array('image/pjpeg', 'image/jpeg');
  6.  
  7.     if (!in_array($file_data_type, $acceptedFileTypes)) {
  8.         echo('Invalid filetype: '.$file_data_type);
  9.         die;
  10.     } else {
  11.         return true;
  12.     }
  13. } // validateType()
  14. ?>

Reply With Quote
  #5  
Old August 10th, 2002, 01:56 PM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: File Upload / File type

I think this may be set in the <input type="file"> tag with the 'accept' attribute...

php Code:
Original - php Code
  1.  
  2. <input type="file" name="pic" accept="image/pjpeg;image/jpeg">

Reply With Quote
  #6  
Old August 10th, 2002, 02:00 PM
cjrobs cjrobs is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Southampton, England
Posts: 121 cjrobs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to cjrobs
RE: File Upload / File type

yes, but as with any client-side thing - that can be bypassed. Client-Side stuff is great for making wizzy effects/design/doing a primary check of forms, but you can't trust anything your script is given from a form - you have to check it with your server-side script to make sure it is valid.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > File Upload / File type


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 6 hosted by Hostway