Jump to content

Trouble using upload script


thedualmind

Recommended Posts

I went through a couple of tutorials before bothering anyone, however I still cannot seem to get past an error from the upload_file_with_validation function. I am new to PHP and I am very eager to learn, however I keep running into walls. I used the Writing A file Upload Class tutorial by BinaryStar which helped me to understand the scripting process much better. My goal right now is just to learn how to get a script to work and there is obviously something I am missing here. I would definitely appreciate anyones help. Here is the script I used. The error message will be posted below it:

 

<?php

function upload_file_with_validation() {

    //SECTION #1

    $temp_file_name = trim($this->temp_file_name);

    $file_name = trim(strtolower($this->file_name));

    $upload_dir = $this->get_upload_directory();

    $upload_log_dir = $this->get_upload_log_directory();

    $file_size = $this->get_file_size();

    $ip = trim($_SERVER['REMOTE_ADDR']);

    $cpu = gethostbyaddr($ip);

    $m = date("m");

    $d = date("d");

    $y = date("Y");

    $date = date("m/d/Y");

    $time = date("h:i:s A");

    $existing_file = $this->existing_file();    //<-Add On

    $valid_user = $this->validate_user();        //<-Add On

    $valid_size = $this->validate_size();        //<-Add On

    $valid_ext = $this->validate_extension();    //<-Add On

 

    //SECTION #2

    if (($upload_dir == "ERROR") OR ($upload_log_dir == "ERROR")) {

        return false;

    }

    elseif ((((!$valid_user) OR (!$valid_size) OR (!$valid_ext) OR ($existing_file)))) {

        return false;

    } else {

        if (is_uploaded_file($temp_file_name)) {

            if (move_uploaded_file($temp_file_name,$upload_dir . $file_name)) {

                $log = $upload_log_dir.$y."_".$m."_".$d.".txt";

                $fp = fopen($log,"a+");

                fwrite($fp,"

$ip-$cpu | $file_name | $file_size | $date | $time");

                fclose($fp);

                return true;

            } else {

                return false;

            }

        } else {

            return false;

        }

    }

}

?>

 

Error Message Appears to be a directory upload problem:

 

Parse error: parse error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/content/t/h/e/thedualmind/html/policy.php on line 16

 

Link to comment
https://forums.phpfreaks.com/topic/61446-trouble-using-upload-script/
Share on other sites

I think we're getting somewhere .  I deleted a file named policy.php in the main html directory. Now when I try to submit the upload on the webpage I get a page now found message which sounds like now we just need to get the right policy.php in the right php folder. 

I think we're getting somewhere .  I deleted a file named policy.php in the main html directory. Now when I try to submit the upload on the webpage I get a page now found message which sounds like now we just need to get the right policy.php in the right php folder. 

 

you really need to find the policy.php thats the only way to sort the prob

 

and one thing for sure you have that file or else you wont have that error message

I have the file posted under the following path: /php_uploads/gdforms.php/policy.php.

However it seems to only recognize the file being present when it is in the main directory, which is the html directory. You think that my directory setup is not good or maybe my form code is the problem. I can post that if you think that could be an issue.

I got the form to go to the policy.php page after being submitted. However, the files did not seem to get uploaded. On my php script for the parts:

 

$upload_dir = $this->get_upload_directory();

    $upload_log_dir = $this->get_upload_log_directory();

 

Do I need to type in my own directory here. If not, is there anywhere in particular that I need to place my actual directory path in the script

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.