Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unexpected T_STRING error?

Status
Not open for further replies.

DGTLguy

Technical User
Jul 23, 2003
125
0
0
US
i'm getting this error msg:

Parse error: parse error, unexpected T_STRING in /home/content/g/3/n/g3nius/html/gallery/eyelash_images/big/upload.php on line 12

my code looks like:

Code:
<form name="form1" method="post" action="" enctype="multipart/form-data"> 
<input type="file" name="imagefile"> 
<br> 
<input type="submit" name="Submit" value="Submit"> 
 <? 
if(isset( $Submit )) 
{ 
//If the Submitbutton was pressed do: 

if ($_FILES['imagefile']['type'] == "image/gif"){ 
        
 copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
     or die ("Could not copy"); 
 
        echo ""; 
         echo "Name: ".$_FILES['imagefile']['name'].""; 
         echo "Size: ".$_FILES['imagefile']['size'].""; 
         echo "Type: ".$_FILES['imagefile']['type'].""; 
         echo "Copy Done...."; 
         } 
 
        else { 
            echo "<br><br>"; 
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; 
        } 
} ?> </form>

line 12 is:

copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
 
DGTLGuy,

You'll want to strip that down to the basename.

Code:
$nwfile = "files/". basename($_FILES['imagefile']['name']);

 copy ($_FILES['imagefile']['tmp_name'], $nwfile)
    or die ("Could not copy");

Also notice in php.net's ex. they use move_uploaded_file() to write the file:


Thanks,


Hope it's helpful.

Good Place to "Learn More">>
 
I copied your source and didn't get any syntax error. But I did notice that you're assuming that register_globals is ON.

You should change the line
Code:
if(isset( $Submit ))
to
Code:
if(isset( $_POST['Submit'] ))

Ken
 
thanks for the replies guys... i made both changes and now I get a new error message:

Parse error: parse error, unexpected T_VARIABLE in /home/content/g/3/n/g3nius/html/upload.php on line 12

line 12 is the line of code from Lrnmore:

$nwfile = "files/". basename($_FILES['imagefile']['name']);
 
This page has been tested and works, I just copied php.net's sample code.
What happens when you upload it to your server and test it?
What is the file value you are trying to pass?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
        <TITLE>Upload Files</TITLE>
</HEAD>

<BODY>
<H1>File Uploader</H1>
<HR>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="fupload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" name="Submit" value="Send File" />
</form>

<?php
if(isset($_POST['Submit'])){
$nwfile = "files/". basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $nwfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
}
?>
</BODY>
</HTML>

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top