Q:

Function not uploading correctly

I am trying to upload images to a directory that is defined on input page and passed to the $path variable within the function. Right now it uploads the image in to the same directory as the upload script and not the defined image folder. I have re-worked this several ways the the result is always the same. Both $path and $this->destination remain empty and the image is uploaded to the wrong place. Can anyone else see what I have done wrong?
<?php
    //set the max upload size in bytes
    $max = 51200;
    if(isset($_POST['upload'])){
        //define path to the upload directory
        $destination = '../../../../image_folder/test/';
        require_once('upload.php');
        try {
            $upload = new Ps2_Upload("$destination");
            $upload->move();
            $result = $upload->getMessages();
        } catch (Exception $e) {
            echo $e->getMessage();
        } 
    }
?>
<!DOCTYPE html>
<html>
    <head>
    <body>
        <?php
            if (isset($result)) {
                echo '<ul>';
                foreach ($result as $message) {
                echo "<li>$message</li>";
            }
                echo '</ul>';
            }

            echo "the place the files will be put is $destination";
        ?> 
        <form action="" method="post" enctype="multipart/form-data" id="uploadImage">
            <label for="image">Upload New Image</label>
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>" />
            <input type="file" name="image" id="image" />
            <input type="submit" name="upload" id="upload" value="Upload" />
        </form>
    </body>
</html>

<?php
class Ps2_Upload {
    //protected variables
    protected $_uploaded = array();
    protected $_destination;
    protected $_max = 51200;
    protected $_messages = array();
    protected $_permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png');
    protected $_renamed = false;

    public function __construct($path){
        if(!is_dir($path) || !is_writable($path)){
            throw new Exception("$path must be a valid, writable directory.");
        }
        $this->_destination = $path;
        $this->_uploaded = $_FILES;
    }

    public function move(){
        $field = current($this->_uploaded);
        $success = move_uploaded_file($field['tmp_name'], $this->destination . $field['name']);
        if($success){
            $this->_messages[] = $field['name'] . " uploaded successfully to $this->destination";
        } else {
            $this->_messages[] = 'Could not upload ' . $field['name'];
        }
    }

    public function getMessages() {
        return $this->_messages;
    } 
}
?>

A:

In your constructor, you have this: $this->_destination = $path;
In your move() method, you have this: $success = move_uploaded_file($field['tmp_name'], $this->destination . $field['name']);
your protected variable is _destination but what you are using in the move() method is destination. No underscore before it. Work on that, might solve your problem:
$success = move_uploaded_file($field['tmp_name'], $this->_destination . $field['name']);

Should work.

