Keresés

Új hozzászólás Aktív témák

  • Lacces

    őstag

    válasz Speeedfire #8467 üzenetére

    Ha simán megadom az abszolút útvonalat, akkor jó. Ki van kommentálva, de amúgy meg nem jó...

    Szerintem adsz egy jó kis linket ahol van ennél jobb :D.
    Könyv példájából van. De amúgy nem rossz, mert sok minden van hozzá, átnevezés, thumbnail create.
    De így is van vele egy nagy gondom... hogy hiába állítok bele fájlméret korlátot, elég rosszul működik. hiába állítom 100mb, 5 megásra kivágja, hogy túl nagy méret, 3 megásat meg elfogad...

    if (isset($_POST['upload'])) {
    // define the path to the upload folder
    // $destination = '/var/www/PHP/images/uploads/';
    $destination = realpath(__DIR__ . '/images/uploads');
    require_once('./classes/Upload.php');
    try {
    $upload = new Upload($destination);
    $upload->setMaxSize($max);
    $upload->move();
    $result = $upload->getMessages();
    } catch (Exception $e) {
    echo $e->getMessage();
    }
    }

    Upload osztályból:

    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;
    }

    protected function processFile($filename, $error, $size, $type, $tmp_name, $overwrite) {
    $OK = $this->checkError($filename, $error);
    if ($OK) {
    $sizeOK = $this->checkSize($filename, $size);
    $typeOK = $this->checkType($filename, $type);
    if ($sizeOK && $typeOK) {
    $name = $this->checkName($filename, $overwrite);
    $success = move_uploaded_file($tmp_name, $this->_destination . $name);
    if ($success) {
    // add the amended filename to the array of filenames
    $this->_filenames[] = $name;
    $message = "$filename uploaded successfully";
    if ($this->_renamed) {
    $message .= " and renamed $name";
    }
    $this->_messages[] = $message;
    } else {
    $this->_messages[] = "Could not upload $filename";
    }
    }
    }

    Szal inkább lehet linket kéne küldeni nekem, hogy mely kód implementálását ajánljátok nekem :D

Új hozzászólás Aktív témák