1

我试图让这个非常基本的脚本将 .swf 文件上传到我的服务器,但没有成功。尝试上传时出现无效文件错误。.jpg,gifs,pngs 都可以上传。

我尝试改变一些东西,将 swf 放在 jpg 所在的位置等,但没有任何乐趣。

这种方式不能上传swf文件吗?

和帮助表示赞赏,非常感谢。

` 文件名:

<?php
 $allowedExts = array("gif", "jpeg", "jpg","swf","png");
 $extension = end(explode(".", $_FILES["file"]["name"]));
 if ((($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/jpeg")
 || ($_FILES["file"]["type"] == "image/jpg")
 || ($_FILES["file"]["type"] == "application/x-shockwave-flash/swf")
 || ($_FILES["file"]["type"] == "image/png"))
 && ($_FILES["file"]["size"] < 8388608)
 && in_array($extension, $allowedExts))
   {
   if ($_FILES["file"]["error"] > 0)
      {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
     }
   else
     {
     echo "Upload: " . $_FILES["file"]["name"] . "<br>";
     echo "Type: " . $_FILES["file"]["type"] . "<br>";
     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
       }
     }
   }
 else
   {
   echo "Invalid file";
   }
 ?> `
4

1 回答 1

0
function addAdFields($post,$files){

    //print_r( $files);

    $allowedExts = array("gif", "jpeg", "jpg", "png" ,"tiff","tif","swf");
    $fileType=$files["bannerType"]["type"];
    $tmpName=$files["bannerType"]["tmp_name"];
    $fileName=$files["bannerType"]["name"];

    $imageName = mysql_real_escape_string($files["bannerType"]["name"]);
    $imageData = mysql_real_escape_string(file_get_contents($files["bannerType"]["tmp_name"]));
    $imageType = mysql_real_escape_string($files["bannerType"]["type"]);
    list($width, $height, $type, $attr) = getimagesize($tmpName);
    $dimArr= array($width, $height);
    $temp = explode(".", $fileName);
    $files["bannerType"]["name"];
    $extension = end($temp);
    $fileTmpName= mysql_real_escape_string($tmpName);
    $curDate = "";
    $ipadd = $_SERVER['REMOTE_ADDR'];
    $camDetail=explode('_',$post['campaignType']);
    $this -> tableName                                      =   "_ads";
    $this -> fieldValues['campaignID']                      =   $camDetail[0];
    $this -> fieldValues['campaignName']                    =$camDetail[1];
    $this -> fieldValues['adTitle']                         =   $post['adTitle'];
    $this -> fieldValues['bannerID']                        =   $post['bannerType'];
    if($_SESSION['bannerTyp']=='Placement')
    {
        $this -> fieldValues['uploadFileName']                  =   $post['placementText'];

    }
    else{
    $this -> fieldValues['uploadFileName']                  =   $imageName;
    $this -> fieldValues['uploadedFile']                    =   $imageData;
    }
    $this -> fieldValues['dimantation']                     =   json_encode($dimArr);
    $this -> fieldValues['addDateTime']                     =   $curDate;
    $this -> fieldValues['addIpAddress']                    =   $ipadd; 
    $this->insert();
    //echo $this->query;
    header('Location: main.html?action=add-ads&menuid=155');
}
于 2013-09-13T07:18:05.383 回答