-1

This is my code:

 <? php
     $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
     $fp = fopen("/test/image.jpg", "w");
     fwrite($fp, $content);
     fclose($fp);
 ?>

And this is the error I get:

Parse error: syntax error, unexpected T_VARIABLE in D:\Host\5164\html\maffick1\test\download.php on line 2

As far as I know, this error comes when you miss a semicolon or bracket. But I have tried everything.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anurag
  • 141
  • 1
  • 3
  • 12

2 Answers2

7

Remove space between question mark and "php" in first line:

<? php

Change this to:

<?php
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
ioseb
  • 16,625
  • 3
  • 33
  • 29
4

Since <? also marks the beginning of a PHP script, the parser will treat your code as:

 <?
 php
 $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
 $fp = fopen("/test/image.jpg", "w");
 fwrite($fp, $content);
 fclose($fp);
 ?>

So it believes you're trying to declare a variable called php, but it's missing the $ sign.

Remove the space:

 <?php
 $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
 $fp = fopen("/test/image.jpg", "w");
 fwrite($fp, $content);
 fclose($fp);
 ?>
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • 3
    Right answer, wrong interpretation of what it is trying to do - it is actually expecting `php` to be the name of a function that is being called, and would be expecting a `(` instead of a variable. It won't think your declaring a variable unless you use a `$`. But +1 for correct solution. – DaveRandom Dec 02 '11 at 08:39