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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse errors, unexpected T_Variable ?

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
US
Hi,

I'm working with a PHP4.1 book - Mastering PHP4.1
Sybex Publishing
Jeremy Allen and Charles Hornberger
(just in case anyone owns the book, they can get a better understanding of what it is I'm talking about.)

on page 285, I'm working with a file upload script, and it tells me I have to modify the variables of $f and $dest_dir but I'm not sure exactly what they want me to change the variables to (not a good explanation on the books part).
So what exactly do I have to change to get this code working correctly??

All I have so far is the code below, and it gives me the error(s) -- Parse error: parse error, unexpected T_VARIABLE in C:\Inetpub\ on line 21


Here's the code from the book that I'm working with.

<?php
//test to make sure we got a file
if(!is_array ($HTTP_POST_FILES['file1'])) {
print ('<html><body>You didn\'t upload a file!</body</html>');
exit;
}

//if we get this far, there must be a file
$f =& $HTTP_POST_FILES['file1']; //saves typing
$dest_dir = 'uploads';
$dest = $dest_dir . '/' . $f['name'];

//make sure the directory exists
if (!is_uploaded_file ($f['tmp_name'])) {
print ('<html><body>Error: No File Uploaded.</body></html>');
exit;
}

if (!file_exists ($dest_dir)) {
print ('<html><body>Error: Destination directory &quot;'
$dest_dir . '&quot; does not exist!</body></html>');
exit;
}

if (!is_dir ($dest_dir)) {
print ('<html><body>Error: Destination Directory &quot;' .
$dest_dir . '&quot;is not a directory!</body></html>');
exit;
}

if (file_exists ($dest)) {
print ('<html><body>Error: File &quot;' . $dest .
. &quot; already exists!</body></html>');
exit;
}

//all clear, move the file to perm location
$r = move_uploaded_file ($f['tmp_name'], $dest);
if ($r ==false
{ //something went wrong
print ('<html><body>Error: Could not copy file to &quot;'
. $dest . '&quot;.</body></html>');
exit;
}
?>

<html><body><p>Your file has been uploaded to <?php print ($dest); ?>.</p>
<p>Click <A href=<?php print ($dest); ?>&quot;here</a> to access the file.
</body></html>


<html><head><title>Upload form v1</title>
</head>

<body>

<form method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;>
<input type=&quot;file&quot; name=&quot;file1&quot; />
</form>


</body>
</html>
 
&quot;Parse error&quot; is the PHP engine's way of saying &quot;I have reached a point where your script code no longer makes any sense to me. I realized this at line X&quot;. It usually signifies a typo somewhere.

Start at line 21 and work your way backwards. Look for unbalanced double quotes, single quotes, parentheses, braces, or brackets.

In your case, look at the section of code which reads:
Code:
if (!file_exists ($dest_dir)) {
    print ('<html><body>Error: Destination directory &quot;'
     $dest_dir . '&quot; does not exist!</body></html>');
    exit;
}

You are missing a &quot;.&quot; at the end of the line which has the word &quot;print&quot; at the beginning of the line. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top