上传 SWF 文件时限制检查条件

Limiting the checking condition while uploading SWF files(上传 SWF 文件时限制检查条件)
本文介绍了上传 SWF 文件时限制检查条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在创建一个使用 PHP 在文件夹中上传 swf 文件的应用程序.我的脚本除了第一个 if 条件(我检查扩展名是否为 swf)外都可以正常工作,但我似乎有一些错误.

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 extension is swf or not, but I seems to have some error.

我不确定 video/swf 是否是 SWF 文件的有效检查参数.我的完整脚本如下.我正在使用 getimagesize() 检查 SWF 的大小.有些人可能想知道 getimagesize 是否适用于图像,但我看到了一些使用 getimagesize() 获取 SWF 文件大小的示例.

I'm not sure whether video/swf is a valid checking parameter for SWF files or not. My full script is below. I'm checking the size of the SWF using getimagesize(). Some people may wonder that getimagesize works for image, but I saw some examples where getimagesize() has been used for getting size of SWF files.

它给我消息无效的 swf 文件",这意味着它根本不满足第一个检查条件.

It's giving me the message "invalid swf file", that means its not satisfying the first checking condition at all.

<?php
        foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
        {

        list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);

        if (( ($_FILES["item_swf"]["type"][$key] == "video/swf") || ($_FILES["item_swf"]["type"][$key] == "video/SWF") )
        && ($_FILES["item_swf"]["size"][$key] < 800000))
           {
                if ($_FILES["item_swf"]["error"][$key] > 0)
                  {
                     echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
                  }
                else if($width==1000 && $height==328)
                  {
                   if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
                            {
                               echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
                             }
                   else
                            { 

                               move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
                               echo "done";
                        }
                  }
             else 
                 {
                    echo "size doest permit";
                 }  
            }
        else
            {
               echo "Not a valid swf file::";
            }                       

        }
        ?>

下面给出的行

move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);

在将文件上传到专用文件夹时运行良好,但不知何故似乎未正确设置仅 SWF 文件的检查参数.

is working perfectly as it is uploading files to the dedicated folder, it somehow seems that the checking parameters for SWF only files are not set properly.

我得到了答案.我需要使用 application/x-shockwave-flash 而不是使用 video/swf.

I got my answer. Instead of using video/swf I need to use application/x-shockwave-flash.

所以最终代码将是:

<?php
        foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
        {

        list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);

        if (($_FILES["item_swf"]["type"][$key] == "application/x-shockwave-flash") 
        && ($_FILES["item_swf"]["size"][$key] < 800000))
           {
                if ($_FILES["item_swf"]["error"][$key] > 0)
                  {
                     echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
                  }
                else if($width==1000 && $height==328)
                  {
                   if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
                            {
                               echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
                             }
                   else
                            { 

                               move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
                               echo "done";
                        }
                  }
             else 
                 {
                    echo "size doest permit";
                 }  
            }
        else
            {
               echo "Not a valid swf file::";
            }                       

        }
        ?>

推荐答案

好的,我得到了答案....

ok, i got my answer....

我需要使用 application/x-shockwave-flash

所以最终代码将是

<?php
        foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
        {

        list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);

        if (( ($_FILES["item_swf"]["type"][$key] == "application/x-shockwave-flash") || ($_FILES["item_swf"]["type"][$key] == "video/SWF") )
        && ($_FILES["item_swf"]["size"][$key] < 800000))
           {
                if ($_FILES["item_swf"]["error"][$key] > 0)
                  {
                     echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
                  }
                else if($width==1000 && $height==328)
                  {
                   if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
                            {
                               echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
                             }
                   else
                            { 

                               move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
                               echo "done";
                        }
                  }
             else 
                 {
                    echo "size doest permit";
                 }  
            }
        else
            {
               echo "Not a valid swf file::";
            }                       

        }
        ?>

这篇关于上传 SWF 文件时限制检查条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Encryption in JavaScript and decryption with PHP(JavaScript 加密和 PHP 解密)
Best solution to protect PHP code without encryption(无需加密即可保护 PHP 代码的最佳解决方案)
PHP AES encrypt / decrypt(PHP AES 加密/解密)
Upgrading my encryption library from Mcrypt to OpenSSL(将我的加密库从 Mcrypt 升级到 OpenSSL)
How to add/remove PKCS7 padding from an AES encrypted string?(如何从 AES 加密字符串中添加/删除 PKCS7 填充?)
How do I upgrade from PHP 7.0 to 7.3 on google cloud platform?(如何在谷歌云平台上从 PHP 7.0 升级到 7.3?)