Autor Zpráva
Tino
Profil *
Mám menšiu chybu pri uploade. Uploadne súbor a hodí toto
Warning: move_uploaded_file(img71a2abc101114ef6f4387e1f664f98efJPG) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/imguploa/public_html/php5upload.class.php on line 101

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpouRFlR' to 'img71a2abc101114ef6f4387e1f664f98efJPG' in /home/*****/public_html/php5upload.class.php on line 101

Tu je celý zdrojak php5upload.class.php
<?php
class imageupload
{
//pblic variables
public $path = '';
public $errorStr = '';
public $imgurl = '';

//private variables
private $_errors = array();
private $_params = array();
private $_lang = array();
private $_maxsize = 1048576;

public $_im_status = false;

//public methods
public function __construct ()
{
require 'config.php';
$this->_types = $types;
$this->_lang = $lang;
$this->_upload_dir = $upload_dir;
$this->_maxsize = $maxsize;

$this->path = $PHP_SELF;

if (is_array($_FILES['__upload']))
{
$this->_params = $_FILES['__upload'];
if (function_exists('exif_imagetype'))
$this->_doSafeUpload();
else
$this->_doUpload();

if (count($this->_errors) > 0)
$this->_errorMsg();
}
}

public function allowTypes ()
{
$str = '';
if (count($this->_types) > 0) {
$str = 'Allowed types: (';
$str .= implode(', ', $this->_types);
$str .= ')';
}

return $str;
}

// private methods
private function _doSafeUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if (exif_imagetype($this->_params['tmp_name']) && in_array(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;

if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -4);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name;
}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}

private function _doUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if(in_array(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;

if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -3);
$this->new_name = md5(time()).$ext;

move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);

$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name;
}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}

function _errorMsg()
{
$this->errorStr = implode('<br />', $this->_errors);
}
}

?>
Megaloman
Profil *
Předpokládám, že v config.php máš definované proměnné $types, $lang, $upload_dir, $maxsize a předpokládám, že řádek 101 je
move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name); ...

Máš práva na zápis do adresáře $this->_upload_dir?


PS: V následujícím řádku asi omylem vypadla tečka:
$this->new_name = md5(time()) . '.' . $ext;

místo

$this->new_name = md5(time()).$ext;

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0