致命错误:Class' Ps2 \ Exception'未找到

时间:2013-03-16 05:32:32

标签: php html mysql

我尝试将图片上传到我的网站时出现以下错误, 它在我的localhost中工作正常,但是当我上传到WebServer时出现此错误

致命错误:第20行的G:\ WebSpace \ siteadress.com \ www \ classes \ ps2 \ upload.php中找不到“Ps2 \ Exception”类

我的upload.php如下,

    <?php
namespace Ps2;
class Upload {
protected $_uploaded = array();
protected $_destination;
protected $_max = 102400;
protected $_messages = array();
protected $_permitted =            array('image/gif','image/jpeg','image/pjpeg','image/png','image/jpg');
protected $_renamed = false;
public $location = null;



public function __construct($path) {
// connect to the database
    mysql_connect("localhost", "prince", "abcd");
    mysql_select_db("tuts");
/*************************************************************/ 
    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($overwrite = false) {
$field = current($this->_uploaded);
$OK = $this->checkError($field['name'], $field['error']);
if ($OK) {
    $sizeOK = $this->checkSize($field['name'], $field['size']);
    $typeOK = $this->checkType($field['name'], $field['type']);
    if ($sizeOK && $typeOK) {
        $name = $this->checkName($field['name'], $overwrite);
        $success = move_uploaded_file($field['tmp_name'], $this->_destination . $name);
        if ($success) {
            $message = $field['name'] . ' uploaded successfully';
            $location = $field['name'];
            if ($this->_renamed) {
                $message .= " and renamed $name";
                $location = $name;
            }
            $this->_messages[] = $message;
        } 
        else {
            $this->_messages[] = 'Could not upload ' . $field['name'];
        }

        /*************************DB***************************/
        mysql_query("INSERT INTO images VALUES('$name')");
    }
}    
}

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

protected function checkError($filename, $error) {
    switch ($error) {
    case 0:
        return true;
    case 1:
    case 2:
        $this->_messages[] = "$filename exceeds maximum size: " . $this->getMaxSize();
        return true;
    case 3:
        $this->_messages[] = "Error uploading $filename. Please try again.";
        return false;
    case 4:
        $this->_messages[] = 'No file selected.';
        return false;
    default:
        $this->_messages[] = "System error uploading $filename. Contact webmaster.";
        return false;
    }
}

protected function checkSize($filename, $size) {
    if ($size == 0) {
        return false;
    } 
    elseif ($size > $this->_max) {
        $this->_messages[] = "$filename exceeds maximum size: " . $this->getMaxSize();
        return false;
    } 
    else {
        return true;
    }
} 

protected function checkType($filename, $type) {
    if (empty($type)) {
        return false;
    } 
    elseif (!in_array($type, $this->_permitted)) {
        $this->_messages[] = "$filename is not a permitted type of file.";
        return false;
    } 
    else {
        return true;
    }
} 

public function getMaxSize() {
    return number_format($this->_max/1024, 1) . 'kB';
}

public function addPermittedTypes($types) {
    $types = (array) $types;
    $this->isValidMime($types);
    $this->_permitted = array_merge($this->_permitted, $types);
} 

public function setPermittedTypes($types) {
    $types = (array) $types;
    $this->isValidMime($types);
    $this->_permitted = $types;
}

public function setMaxSize($num) {
    if (!is_numeric($num)) {
        throw new Exception("Maximum size must be a number.");
    }
    $this->_max = (int) $num;
} 

protected function checkName($name, $overwrite) {
    $nospaces = str_replace(' ', '_', $name);
    if ($nospaces != $name) {
        $this->_renamed = true;
    }
    if (!$overwrite) {
        // rename the file if it already exists
        $existing = scandir($this->_destination);
        if (in_array($nospaces, $existing)) {
            $dot = strrpos($nospaces, '.');
            if ($dot) {
                $base = substr($nospaces, 0, $dot);
                $extension = substr($nospaces, $dot);
            } 
            else {
                $base = $nospaces;
                $extension = '';
            }
            $i = 1;
            do {
            $nospaces = $base . '_' . $i++ . $extension;
            } 
            while (in_array($nospaces, $existing));
            $this->_renamed = true;
        }
    }
    return $nospaces;
    echo $nospaces;
}   


}  

0 个答案:

没有答案