PDA

View Full Version : php seems to hate my function line


mr_flea
11-15-04, 23:01
I have a small script on my site used for uploading files, but I can't seem to get it to work. I've tried everything I can think of and I still get the error

Parse error: parse error, expecting `')'' in F:\Files\HTML code and website files\upload5.php on line 8

I've ran out of ideas as to how to fix this. Anyone else have any ideas?
Page (http://www.deepblueice.com/upload4.php)
Source (http://www.deepblueice.com/upload4.txt)

Wookie
11-16-04, 08:24
Here ya go

First thing to remember

if(condition){
}
elseif(condition){ }


always put your comparison in the ( )

As for the function it was giving me an error until I stuck a variable name there, When you call the function you are passing it a string so you need to have a variable there to accept it and the /" could have been causing a problem. This worked for me tho. Not sure if it works how u want it I didnt test but it loads.



<html>
<head>
<title>DeepBlueIce File Upload</title>
</head>
<body>
<?PHP
function upload($test2, $test) {
if ($_POST['psw'] == "") {
$auth = 1;
}
elseif ($_POST['psw'] == "password1") {
$auth = 2;
}
elseif ($_POST['psw'] == "password2") {
$auth = 3;
}
else {
$auth = 1;
}
if ($_FILES['file']['name'] == "") {
return "Invalid File Name Specified.";
}
elseif ($auth == 1) {
if ($_FILES['file']['size'] > 500000) {
return "The file was over 500K.";
}
}
elseif ($_FILES['file']['type'] == "text/plain") {
return "You cannot upload text/script files.";
}


elseif ($auth == 2) {
if ($_FILES['file']['size'] > 5000000) {
return "The file was over 5MB.";
}
}
elseif ($auth == 3) {}
$result = move_uploaded_file($_FILES['file']['tmp_name'], "files/".$_FILES['file']['name']);
$message = ($result)?"File url <a href=upload.deepblueice.com/".$_FILES['file']['name'].">upload.deepblueice.com/".$_FILES['file']['name']."</a>" : "An unknown error occurred. Use

the contact page to bother me about it. Please include details as to how it occurred.";
return $message;
}


if (isset($_POST['upload'])) {upload("files/", "http://www.deepblueice.com/files/");}
else {echo "DeepBlueIce File Upload";}

?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
<input type="file" id="file" name="file">
<input type="password" id="psw" name="psw">
<input type="submit" id="upload" name="upload" value="Upload!">
</form>
The password is required to upload files in excess of 500K or text/script files. Otherwise, it is not needed.
</body>
</html>

goldfish
11-16-04, 12:30
Yep, wookie is right.

Also, I would be careful with filenames. If you're uploading from a windows system to a linux system, you can get some problems there.

Normally, I'd solve this using a database, giving each file a record and using the ID of the record as the filename, with the original extension. It also gives you a convineint way to list and manage files, as well as other information about them (e.g. user name, the date/time they were uploaded etc.)

mr_flea
11-16-04, 21:01
Yep, wookie is right.

Also, I would be careful with filenames. If you're uploading from a windows system to a linux system, you can get some problems there.

Normally, I'd solve this using a database, giving each file a record and using the ID of the record as the filename, with the original extension. It also gives you a convineint way to list and manage files, as well as other information about them (e.g. user name, the date/time they were uploaded etc.)
But then wouldn't you have to put the id number in to get the file?? That kinda defeats the purpose...

Wookie: Thanks, that worked great :)