php seems to hate my function line

Discussion in 'Software' started by mr_flea, Nov 16, 2004.

  1. mr_flea

    mr_flea First Sergeant

    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
    Source
     
  2. Wookie

    Wookie Sergeant Major

    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.


    Code:
    <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>
    
     
  3. goldfish

    goldfish Lt. Sushi.DC

    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.)
     
  4. mr_flea

    mr_flea First Sergeant

    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 :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds