I have a bit of a problem with my code. I am trying to set up a simple way to upload a file, and by able to view it publicly. This script should be able to:
1) Accept the file and add random 3-digit prefix (
nnnfile.txt)
2) Check if
nnnfile.txt exists
2A) If it does, change the prefix to a 4-digit prefix (
nnnnfile.txt)
2B) If it doesn't, move it from /tmp/php to /var/www/phaux.ath.cx/htdocs/uploads
3) Make a varible $file to the files location.
Simple? Heres the code. When I run it, it spits out:
Quote:
Parse error: parse error, unexpected $ in /var/www/phaux.ath.cx/htdocs/upload.php on line 21
|
Count the lines and tell me whats wrong with this script.
PHP Code:
<?php require('/inc/header.inc') ?>
<?php
$uploadfolder = "/var/www/phaux.ath.cx/htdocs/uploads/";
$rand1 = rand(100, 999);
if(is_uploaded_file($_FILES['uploaded']['tmp_name'])) {
if(file_exists("{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}")) {
$rand2 = rand(1000, 9999);
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}");
$file = "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}";
} else {
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}");
$file = "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}";
}
?>
<FORM METHOD="POST" ACTION="upload.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="uploaded"> <INPUT TYPE="submit" VALUE="Upload">
</FORM>
<?php require('/inc/footer.inc') ?>
Notice how theres no line 21?