0

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

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

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

<?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 文件的检查参数似乎设置不正确。

编辑

我得到了我的答案。而不是使用video/swf我需要使用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::";
            }                       

        }
        ?>
4

2 回答 2

1

你可以试试

$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);
}

如果您还有其他挑战,请告诉我

于 2012-04-14T08:24:45.610 回答
0

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

而不是使用video/swf我需要使用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::";
            }                       

        }
        ?>
于 2012-04-15T04:46:44.510 回答