By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

Php extension error

P: 2
Hey guys i get something im not suppose to get when i run this script. The problem is when i select a jpg picture it still says :FILE MUST Be jpg/jpeg ..im running this on localhost php ver 5.3.8. Would appreciate if u could help god bless u

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_FILES['file']['name'];
  4. $type = $_FILES['file']['type'];
  5. $extension = strtolower(substr($name , strpos($name , '.'))+ 1 );
  6. $tmp_name =$_FILES['file']['tmp_name'];
  7.  
  8.  
  9.  
  10. if(isset($name)){
  11.  if(!empty($name)){
  12.  
  13.    if(($extension=='jpg' or $extension=='jpeg')&& $type=='image/jpeg'){
  14.  
  15.       $location = 'uploads/';
  16.  
  17.     if(move_uploaded_file($tmp_name , $location.$name)) {
  18.        echo 'DONE';
  19.     }else{
  20.        echo "ERROR";
  21.     }
  22.    }else{
  23.        echo 'FILE  MUST Be jpg/jpeg';
  24.     }
  25.    }else {
  26.       echo 'PLZ SELECT A FILE';
  27.    }
  28.  }
  29.  
  30.  
  31. ?>
  32.  
  33. <form action='uploadextension.php' method="POST" enctype="multipart/form-data">
  34.   <input type="file"  name ="file"><br><br>
  35.   <input type="submit" value='UPLOAD'>
  36. </form>
Dec 16 '11 #1

✓ answered by johny10151981

look at this line:
Expand|Select|Wrap|Line Numbers
  1. //strtolower(substr($name , strpos($name , '.'))+ 1 );
  2. //substr($name , strpos($name , '.'))+ 1 //what does it return? probably zero but not your string.
  3.  
  4. //your line would be
  5. strtolower(substr($name , strpos($name , '.')+1));
  6.  

Share this Question
Share on Google+
2 Replies


100+
P: 1,059
look at this line:
Expand|Select|Wrap|Line Numbers
  1. //strtolower(substr($name , strpos($name , '.'))+ 1 );
  2. //substr($name , strpos($name , '.'))+ 1 //what does it return? probably zero but not your string.
  3.  
  4. //your line would be
  5. strtolower(substr($name , strpos($name , '.')+1));
  6.  
Dec 17 '11 #2

P: 2
ya that solved it thks bro u rock!
Dec 22 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.