No, here's what you should have:

$types = array('application/x-shockwave-flash','application/inset_another_type_here');
$file = $_FILES['type']['insert_type_here'];
if (!in_array($file,$types))
echo "sorry, the files of type '$file' are not supported";

Looks like you need to learn how to use arrays. Can't code PHP without em. 😉

    Heh, i get all eccept where insert_type_here is. Wouldnt it be ['file']['type']?

      Arrgh, im getting very confused

        Did you test the code you wrote? What are the errors? What is it doing that you don't want it to do?

        Did you remember the {} for the if statement I see they are missing in the examples...

          I got:

          sorry, the files of type '' are not supported

          Code snippet (Direct copy from the file):

          elseif ($_FILES['file']['size'] > $max_filesize){
          
          echo "Error! flash file must not be bigger than 3 MB  <a href='?'>Go back?</a>";
          
          }
          
          $types = array('application/x-shockwave-flash','image/gif','image/jpeg','image/png');
          $file = $_FILES['type']['insert_type_here'];
          if (!in_array($file,$types))
          echo "sorry, the files of type '$file' are not supported"; 
          
          
          elseif(file_exists($upload.$filename)){
          
          echo "Error! File already exists on server, rename and try again. <a href='?'>Go back?</a>";
          
          }

            It looks like all you are doing is checking the file extintion for what type of file it is, so what you worte before should work just fine.

            $types = array('.swf','.jpg','.png');
                $file = '$_FILES';
                if (!in_array($file,$types)) {
                    echo "sorry, the files of type '$file' are not supported"; 
            }
            

              Nope, I got:

              sorry, the files of type '$_FILES' are not supported

              while trying to upload a .swf

              And what im doing is checking the extention and if it is not what I have listed it will not get through, otherwise, it continues.

                Do you have the $_FILES value set else where? If not try:

                $file = $_GET['FILES'];
                

                or depending on your form method

                $file = $_POST['FILES'];
                

                  Most of the code:

                  <?php
                  
                  if ($_GET['submit']){
                  
                  
                  
                  $username=addslashes(strip_tags($_POST['user']));
                  
                  $title=addslashes(strip_tags($_POST['title']));
                  
                  $desc=addslashes(strip_tags($_POST['desc']));
                  
                  $wide=addslashes(strip_tags($_POST['wide']));
                  
                  $high=addslashes(strip_tags($_POST['high']));
                  
                  $cat=addslashes(strip_tags($_POST['catergory']));
                  
                  $max_filesize = 3000000;
                  
                  $filename=rand(500,2000).$_FILES['file']['name'];
                  
                  
                  
                  if ($title == ""){
                  
                  echo "Field title left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif($username == ""){
                  
                  echo "Username Field left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif($desc == ""){
                  
                  echo "Field desccription left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif ($wide == ""){
                  
                  echo "Field width left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif ($high == ""){
                  
                  echo "Field height left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif ($cat == ""){
                  
                  echo "Field catergory left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif (!is_numeric($wide) || !is_numeric($high)){
                  
                  echo "Field width or height false <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif ($_FILES['file']['name'] == "") {
                  
                  echo "Field flash file left blank <a href='?'>Go back?</a>";
                  
                  }
                  
                  elseif ($_FILES['file']['size'] > $max_filesize){
                  
                  echo "Error! flash file must not be bigger than 3 MB  <a href='?'>Go back?</a>";
                  
                  }
                  
                  $types = array('.swf','.jpg','.png');
                      $file = '$_FILES';
                      if (!in_array($file,$types)) {
                          echo "sorry, the files of type '$file' are not supported"; 
                  }
                  
                  
                  elseif(file_exists($upload.$filename)){
                  
                  echo "Error! File already exists on server, rename and try again. <a href='?'>Go back?</a>";
                  
                  }
                  
                  else{
                  
                  $upload = dirname(__FILE__)."/uploads/";
                  
                  copy($_FILES['file']['tmp_name'],$upload.$filename) or die("<br>Error! Couldn't upload file! <a href='?'>Go back?</a>");
                  
                  $size=$_FILES['file']['size'];
                  

                  So I dont have really what you said.

                  And I just use a normal form:

                  <td>File:</td><td><input type="file" name="file">

                    try checking it against $filename, so it would be.

                    $types = array('.swf','.jpg','.png');
                    
                    if (!in_array($filename,$types)) {
                        echo "sorry, the files of type '$file' are not supported"; 
                    }

                      I uploaded a .swf file again and got:

                      sorry, the files of type '/tmp/phpXXO81k' are not supported

                      😕

                        ok, I have one more thing left for you to try and then your at the limit of what I know...

                        function file_ext($key) { 
                        	$key=strtolower(substr(strrchr($key, "."), 1));
                        	$key=str_replace("jpeg", "jpg", $key);
                        	$key=str_replace("JPG", "jpg", $key);
                        	$key=str_replace("GIF", "gif", $key);
                            return($key); 
                        }
                        
                        $types = array('.swf','.jpg','.png');
                            $file = '$_FILES';
                            if ((!in_array(file_ext($file)),$types)) {
                                echo "sorry, the files of type '$file' are not supported"; 
                        }
                        
                        

                        I use this on a photo album I have, I'm reading out of a directory but it should be basicly the same.

                          Parse error: parse error, unexpected ',' in /homepages/11/d152863093/htdocs/bp_up/upload.php on line 126

                          That is if ((!in_array(file_ext($file)),$types)) {

                          And you cant take the , out because then it will say unexpected variable :glare:

                            I think I added an extra ) try taking one out before the ,

                              It looks like that, but I get:

                              Parse error: parse error, unexpected '{' in /homepages/11/d152863093/htdocs/bp_up/upload.php on line 126

                              Hmmmmn

                                well I tried my best... if I think of anything else I'll be sure to post it...

                                added bit... try taking one of the ) off the end also

                                  Well, thanks for trying anyway.

                                  Hmm....

                                    I got it to work with this:

                                    $filetypes = array('application/x-shockwave-flash', 'another here, keep adding');
                                    
                                    .....
                                    elseif (!in_array($_FILES['file']['type'], $filetypes) {
                                      echo "Filetype not allowed";]
                                    }

                                    Thanks for all you guys help though! 😃

                                      7 days later

                                      Good to hear your got your problem figured out.

                                      In retrospect, the problem with your previous code:

                                      elseif ($_FILES['file']['size'] > $max_filesize){
                                      
                                      echo "Error! flash file must not be bigger than 3 MB  <a href='?'>Go back?</a>";
                                      
                                      }
                                      
                                      $types = array('application/x-shockwave-flash','image/gif','image/jpeg','image/png');
                                      $file = $_FILES['type']['insert_type_here'];
                                      if (!in_array($file,$types))
                                      echo "sorry, the files of type '$file' are not supported"; 
                                      
                                      
                                      elseif(file_exists($upload.$filename)){
                                      
                                      echo "Error! File already exists on server, rename and try again. <a href='?'>Go back?</a>";
                                      
                                      }
                                      

                                      was this line:

                                      $file = $_FILES['type']['insert_type_here'];
                                      

                                      which should have read:

                                      $file = $_FILES['file']['type'];
                                      

                                      then this line would have worked:

                                      if (!in_array($file,$types))
                                      echo "sorry, the files of type '$file' are not supported";
                                      

                                      😃

                                        Write a Reply...