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

时间:2023-01-20
本文介绍了上传 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 文件时限制检查条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:做一个视频分享网站,需要一个视频播放器 下一篇:向老式文件上传添加不显眼的进度条

相关文章

最新文章