写入图像文件空白页时,Fwrite产生0字节

时间:2018-10-11 07:59:13

标签: php

我对php很陌生。我想知道如何修改此代码,以便写入图像文件而不是空白文件。谢谢您的帮助。第一个代码是文件wget.php,第二个代码是report_snapshot_upload.php。由于某种原因,我无法识别正在写入的文件,但是有0个字节。我为自己的无知表示歉意,因为我现在才编码几个月。有人从我列出的两个文件中知道我丢失了什么吗?

  <?php
$type = 'image/'.$_GET['type'];
$url = urldecode($_GET['url']);
/*if (filter_var($url, FILTER_VALIDATE_URL) === FALSE){
    die('Not a valid URL');
}else{*/

//}
if(strpos($url,".jpeg") != false || strpos($url,".jpg") != false || strpos($url,".png") != false || strpos($url,".gif") != false || (strpos($url,"facebook") != false && strpos($url,".php") == false && strpos($url,".asp") == false && strpos($url,".aspx") == false && strpos($url,".cgi") == false)){
    $file = file_get_contents($url);
}else{
     die('Not a valid URL');
}

header('Content-Type:'.$type);
echo $file;
?>

<?php
//this file is called by index.swf when a report is made
$siteId  = $_GET["siteId"];//user's id as sent by the siteID var in avc_settings.xxx
$type = $_GET["type"];//snapshot type (text-chat snapshot or camera snapshot);

//make the folder if it's missing
if(!file_exists("report_snaps")){

    $oldmask = umask(0);
mkdir("report_snaps", 0777);
umask($oldmask);




}

//check for malicious $type values
if($type!="TEXT.jpg" && $type !="CAM.jpg"){
    die("save=failed");
}

$image = fopen("report_snaps/".$siteId."_".$type,"wb");
if ($image){
    if (fwrite($image, file_get_contents("php://input"))){
        fclose($image);

        echo "save=ok";
    }else{
        echo "save=failed";
    }
}else{
    echo "save=failed";
}

?>

0 个答案:

没有答案