I am very new to php. I would like to know how I can modify this code so that the image file is written and not blank. Thank-you for your assistance. The first code is file wget.php and the second is report_snapshot_upload.php. For some reason which I have unable to identify the file is being written but with 0 bytes. I apologize for my ignorance, as I have only been coding for a few months now. Does anybody know from the two files that I have listed, what I am missing?
<?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";
}
?>