Limiting the checking condition while uploading SWF files

前端 未结 2 1183
轮回少年
轮回少年 2020-12-12 06:10

I am creating an application of uploading swf files in a folder using PHP. My script is all working except for the first if condition where I\'m checking whether the extensi

2条回答
  •  悲&欢浪女
    2020-12-12 06:40

    you can try

    $savePath = "PATH_TO_SAVE";
    $errors = array ();
    $output = array ();
    //
    
    if (isset ( $_FILES ['item_swf'])) {
    
        foreach ( $_FILES ['item_swf'] ['tmp_name'] as $key => $val ) {
    
            $fileName = $_FILES ['item_swf'] ['name'] [$key];
            $fileSize = $_FILES ['item_swf'] ['size'] [$key];
            $fileTemp = $_FILES ['item_swf'] ['tmp_name'] [$key];
    
            $fileExtention = pathinfo ( $fileName, PATHINFO_EXTENSION );
            $fileExtention = strtolower ( $fileExtention );
    
            if ($fileExtention != ".swf") {
                $errors [$fileName] [] = "Invalid File Extention";
                continue;
            }
    
            if ($fileSize > 800000) {
                $errors [$fileName] [] = "File Too large";
                continue;
            }
    
            list ( $width, $height ) = getimagesize ( $fileTemp );
    
            if ($width != 1000 && $height != 328) {
                $errors [$fileName] [] = "Wrong File dimention ";
                continue;
            }
    
            if (file_exists ( $savePath . DIRECTORY_SEPARATOR . $fileName )) {
                $errors [$fileName] [] = "File Exist";
                continue;
            }
    
            if(!is_writable($savePath ))
            {
                $errors [$fileName] [] = "File Destination not writeable";
            }
    
    
            if(count($errors [$fileName]) == 0)
            {
                if(@move_uploaded_file ( $fileTemp, $savePath . DIRECTORY_SEPARATOR . $fileName))
                {
                    $output[$fileName] == "OK" ;
                }
                else
                {
                    $errors [$fileName] [] = "Error Saving File";
                }
    
            }
    
    
        }
            var_dump($errors, $output);
    }
    

    Let me know if you have any more challenge

提交回复
热议问题