tags:

views:

140

answers:

5

For some reason, when using this code the file it outputs is just called ".jpg".

<?
$title = $GET['title'];
$url = $GET['url'];

$ourFileName = $title.jpg;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

$ch = curl_init ("http://www.address.com/url=$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen("images/$ourFileName",'w');
fwrite($fp, $rawdata);
fclose($fp); 

echo ("<img src=images/$ourFileName>");
?>

Pretty sure it has to do with declaring $ourFileName, any help would be appreciated.

+1  A: 

Looks like it should be the following:

$ourFileName = $title.'.jpg';
John McCollum
+1  A: 

Looks like this line

$ourFileName = $title.jpg;

Should be

$ourFileName = $title . ".jpg";

That should do it as long as you are sure there is a value in $_GET['title'];

neilc
+1  A: 

Surely should be

$title = $_GET['title'];
$url = $_GET['url'];
$ourFileName = $title.'.jpg';

Looks like a world of security problems there though! A script that overwrites any file it has permissions to with a file of an attackers choosing!

Paul Dixon
+3  A: 

Are you sure $GET['title'] is correct? The superglobal variable for accessing the GET parameter values is $_GET, not $GET.

bluebrother
+2  A: 

Try this $ourFileName = $title . ".jpg";