xWastedMindx
Technical User
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 "'
$dest_dir . '" does not exist!</body></html>');
exit;
}
if (!is_dir ($dest_dir)) {
print ('<html><body>Error: Destination Directory "' .
$dest_dir . '"is not a directory!</body></html>');
exit;
}
if (file_exists ($dest)) {
print ('<html><body>Error: File "' . $dest .
. " 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 "'
. $dest . '".</body></html>');
exit;
}
?>
<html><body><p>Your file has been uploaded to <?php print ($dest); ?>.</p>
<p>Click <A href=<?php print ($dest); ?>"here</a> to access the file.
</body></html>
<html><head><title>Upload form v1</title>
</head>
<body>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file1" />
</form>
</body>
</html>
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 "'
$dest_dir . '" does not exist!</body></html>');
exit;
}
if (!is_dir ($dest_dir)) {
print ('<html><body>Error: Destination Directory "' .
$dest_dir . '"is not a directory!</body></html>');
exit;
}
if (file_exists ($dest)) {
print ('<html><body>Error: File "' . $dest .
. " 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 "'
. $dest . '".</body></html>');
exit;
}
?>
<html><body><p>Your file has been uploaded to <?php print ($dest); ?>.</p>
<p>Click <A href=<?php print ($dest); ?>"here</a> to access the file.
</body></html>
<html><head><title>Upload form v1</title>
</head>
<body>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file1" />
</form>
</body>
</html>