Grafische gevorderde |
|
Ik heb het volgende upload script:
<?
class upload {
var $temp_file_name = "";
var $file_name = "";
var $upload_dir = "";
var $upload_log_dir = "";
var $file_prefix = "";
var $max_file_size = "";
var $max_width = "";
var $max_height = "";
var $thumb_width = "";
var $thumb_height = "";
var $ext_array = array();
var $sess_id = "";
function valExtension() {
$file_name = trim($this->file_name);
$extension = strtolower(strrchr($file_name, "."));
$ext_array = $this->ext_array;
$ext_count = count($ext_array);
if(!$file_name) {
return false;
} else {
if(empty($ext_array)) {
return true;
} else {
foreach($ext_array as $val) {
$first_char = substr($val, 0, 1);
if($first_char <> ".") {
$extensions[] = "." . strtolower($val);
} else {
$extensions[] = strtolower($val);
}
}
foreach($extensions as $val) {
if($val == $extension) {
$valid_extension = true;
}
}
if($valid_extension == true) {
return true;
} else {
return false;
}
}
}
}
function valSize() {
$temp_file_name = trim($this->temp_file_name);
$max_file_size = trim($this->max_file_size);
if($temp_file_name) {
$size = filesize($temp_file_name);
if($size > $max_file_size) {
return false;
} else {
return true;
}
} else {
return false;
}
}
function fileExist() {
$file_name = trim($this->file_name);
$upload_dir = $this->getUploadDir();
if($upload_dir == false) {
return true;
} else {
$file = $upload_dir . $file_name;
if(file_exists($file)) {
return true;
} else {
return false;
}
}
}
function fileSizes() {
$temp_file_name = trim($this->temp_file_name);
if($this->max_width) {
$file = imagecreatefromjpeg($temp_file_name);
$x = imagesx($file);
$y = imagesy($file);
if($x > $this->max_width || $y > $this->max_width) {
return false;
} else {
return true;
}
imagedestroy($file);
return true;
} else {
return false;
}
}
function getFileSize() {
$temp_file_name = trim($this->temp_file_name);
$kb = 1024;
$mb = 1024 * $kb;
if($temp_file_name) {
$size = filesize($temp_file_name);
if($size < $kb) {
$file_size = $size . "Bytes";
} elseif($size < $mb) {
$file_size = $size . "Kb";
} else {
$file_size = $size . "Mb";
}
} else {
$file_size = header("Location: error.php?eid=5");
}
return $file_size;
}
function getMaxSize() {
$max_file_size = trim($this->max_file_size);
$kb = 1024;
$mb = 1024 * $kb;
if($max_file_size) {
if($max_file_size < $kb) {
$max_file_size = $max_file_size . "Bytes";
} elseif($max_file_size < $mb) {
$final = round($max_file_size/$kb, 2);
$max_file_size = $final . "Kb";
} else {
$final = round($max_file_size/$mb, 2);
$max_file_size = $final . "Mb";
}
} else {
$max_file_size = header("Location: error.php?eid=5");
}
return $max_file_size;
}
function getUploadDir() {
print('blaat');
$upload_dir = trim($this->upload_dir);
if($upload_dir) {
$dir_lenght = strlen($upload_dir);
$last_slash = substr($upload_dir, $dir_lenght-1, 1);
if($last_slash <> "/") {
$upload_dir = $upload_dir . "/";
}
$handle = @opendir($upload_dir);
$handle = @opendir($upload_log_dir);
if($handle) {
closedir($handle);
} else {
mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/thumb", 0777);
$upload_log_dir = false;
}
} else {
$upload_dir = false;
}
return $upload_dir;
}
function getUploadLogDir() {
$upload_log_dir = trim($this->upload_log_dir);
if($upload_log_dir) {
$dir_lenght = strlen($upload_log_dir);
$last_slash = substr($upload_log_dir, $dir_lenght-1, 1);
if($last_slash <> "/") {
$upload_log_dir = $upload_log_dir . "/";
}
$handle = @opendir($upload_log_dir);
if($handle) {
closedir($handle);
} else {
mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/logs", 0777);
$upload_log_dir = false;
}
} else {
$upload_log_dir = true;
}
return $upload_log_dir;
}
function fileRename() {
$file_name = trim(strtolower($this->file_name));
$split_file = explode(".", $file_name);
$ext = array_pop($split_file);
$file_name = $this->file_prefix . $this->sess_id . "." . $ext;
return $file_name;
}
function createThumb() {
$upload_dir = $this->getUploadDir();
$file_name = $this->fileRename();
$mwidth = $this->thumb_width;
$mheight = $this->thumb_height;
$split_file = explode(".", $file_name);
$ext = array_pop($split_file);
$thumb_name = "thumb/" . $this->file_prefix . $this->sess_id . ".". $ext;
if($ext == "jpg" || $ext == "jpeg") {
$thumb = imagecreatefromjpeg($upload_dir . $file_name);
$thumbx = imagesx($thumb);
$thumby = imagesy($thumb);
if($mwidth <= 0 || $mwidth >= $thumbx) {
$mwidth = $thumbx;
}
$mheight = ($thumbx*($mwidth/$thumbx));
if($thumbx > $thumby) {
$width = $mwidth;
$height = ($thumby*($mheight/$thumbx));
}
if($thumbx < $thumby) {
$width = ($thumbx*($mwidth/$thumby));
$height = $mheight;
}
if($thumbx == $thumby) {
$width = $mwidht;
$height = $mheight;
}
$thumbImg = imagecreatetruecolor($width, $height);
imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby);
imagejpeg($thumbImg, $upload_dir . $thumb_name, 100);
imagedestroy($thumb);
imagedestroy($thumbImg);
} elseif ($ext == "png") {
$thumb = imagecreatefrompng($upload_dir . $file_name);
$thumbx = imagesx($thumb);
$thumby = imagesy($thumb);
if($mwidth <= 0 || $mwidth >= $thumbx) {
$mwidth = $thumbx;
}
$mheight = ($thumbx*($mwidth/$thumbx));
if($thumbx > $thumby) {
$width = $mwidth;
$height = ($thumby*($mheight/$thumbx));
}
if($thumbx < $thumby) {
$width = ($thumbx*($mwidth/$thumby));
$height = $mheight;
}
if($thumbx == $thumby) {
$width = $mwidht;
$height = $mheight;
}
$thumbImg = imagecreatetruecolor($width, $height);
imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby);
imagejpeg($thumbImg, $upload_dir . $thumb_name, 100);
imagedestroy($thumb);
imagedestroy($thumbImg);
}
}
function noValidation() {
$temp_file_name = trim($this->temp_file_name);
$file_name = $this->fileRename();
$upload_dir = $this->getUploadDir();
$upload_log_dir = $this->getUploadLogDir();
$file_size = $this->getFileSize();
$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");
if($upload_dir == false || $upload_log_dir == false) {
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, $this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />");
fclose($fp);
if($stat == true) {
$this->createThumb();
}
mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error());
return true;
} else {
return false;
}
} else {
return false;
}
}
}
function fileValidation($stat) {
$temp_file_name = trim($this->temp_file_name);
$file_name = $this->fileRename();
$upload_dir = $this->getUploadDir();
$upload_log_dir = $this->getUploadLogDir();
$file_size = $this->getFileSize();
$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");
$existing_file = $this->fileExist();
$valid_ext = $this->valExtension();
if($upload_dir == false || $upload_log_dir == false) {
return false;
print('a');
} elseif ($existing_file == true ||$valid_ext == false) {
return false;
print('b');
} else {
print('c');
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,$this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />");
fclose($fp);
if($stat == true) {
$this->createThumb();
}
mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error());
return true;
} else {
return false;
}
} else {
return false;
}
}
}
}
$upload = new upload;
chmod("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam, 0777);
if(is_uploaded_file($_FILES['bestand']['tmp_name'])) {
$upload->temp_file_name = trim($_FILES['bestand']['tmp_name']);
$upload->file_name = trim(strtolower($_FILES['bestand']['name']));
$upload->upload_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam;
$upload->upload_log_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam."/logs";
$upload->file_prefix = "foto_";
$upload->thumb_width = 250;
$upload->thumb_height = 150;
$upload->ext_array = array(".jpg", ".jpeg", ".png");
$upload->sess_id = $naam;
$uploadFile = $upload->fileValidation(true);
}
?>
<? class upload { var $temp_file_name = ""; var $file_name = ""; var $upload_dir = ""; var $upload_log_dir = ""; var $file_prefix = ""; var $max_file_size = ""; var $max_width = ""; var $max_height = ""; var $thumb_width = ""; var $thumb_height = ""; var $ext_array = array(); var $sess_id = ""; function valExtension() { $file_name = trim($this->file_name); $ext_array = $this->ext_array; $ext_count = count($ext_array); if(!$file_name) { return false; } else { return true; } else { foreach($ext_array as $val) { $first_char = substr($val, 0, 1); if($first_char <> ".") { } else { } } foreach($extensions as $val) { if($val == $extension) { $valid_extension = true; } } if($valid_extension == true) { return true; } else { return false; } } } } function valSize() { $temp_file_name = trim($this->temp_file_name); $max_file_size = trim($this->max_file_size); if($temp_file_name) { if($size > $max_file_size) { return false; } else { return true; } } else { return false; } } function fileExist() { $file_name = trim($this->file_name); $upload_dir = $this->getUploadDir(); if($upload_dir == false) { return true; } else { $file = $upload_dir . $file_name; return true; } else { return false; } } } function fileSizes() { $temp_file_name = trim($this->temp_file_name); if($this->max_width) { $file = imagecreatefromjpeg($temp_file_name); $x = imagesx($file); $y = imagesy($file); if($x > $this->max_width || $y > $this->max_width) { return false; } else { return true; } imagedestroy($file); return true; } else { return false; } } function getFileSize() { $temp_file_name = trim($this->temp_file_name); $kb = 1024; $mb = 1024 * $kb; if($temp_file_name) { if($size < $kb) { $file_size = $size . "Bytes"; } elseif($size < $mb) { $file_size = $size . "Kb"; } else { $file_size = $size . "Mb"; } } else { $file_size = header("Location: error.php?eid=5"); } return $file_size; } function getMaxSize() { $max_file_size = trim($this->max_file_size); $kb = 1024; $mb = 1024 * $kb; if($max_file_size) { if($max_file_size < $kb) { $max_file_size = $max_file_size . "Bytes"; } elseif($max_file_size < $mb) { $final = round($max_file_size/$kb, 2); $max_file_size = $final . "Kb"; } else { $final = round($max_file_size/$mb, 2); $max_file_size = $final . "Mb"; } } else { $max_file_size = header("Location: error.php?eid=5"); } return $max_file_size; } function getUploadDir() { $upload_dir = trim($this->upload_dir); if($upload_dir) { $dir_lenght = strlen($upload_dir); $last_slash = substr($upload_dir, $dir_lenght-1, 1); if($last_slash <> "/") { $upload_dir = $upload_dir . "/"; } $handle = @opendir($upload_log_dir); if($handle) { } else { mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/thumb", 0777); $upload_log_dir = false; } } else { $upload_dir = false; } return $upload_dir; } function getUploadLogDir() { $upload_log_dir = trim($this->upload_log_dir); if($upload_log_dir) { $dir_lenght = strlen($upload_log_dir); $last_slash = substr($upload_log_dir, $dir_lenght-1, 1); if($last_slash <> "/") { $upload_log_dir = $upload_log_dir . "/"; } $handle = @opendir($upload_log_dir); if($handle) { } else { mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/logs", 0777); $upload_log_dir = false; } } else { $upload_log_dir = true; } return $upload_log_dir; } function fileRename() { $split_file = explode(".", $file_name); $file_name = $this->file_prefix . $this->sess_id . "." . $ext; return $file_name; } function createThumb() { $upload_dir = $this->getUploadDir(); $file_name = $this->fileRename(); $mwidth = $this->thumb_width; $mheight = $this->thumb_height; $split_file = explode(".", $file_name); $thumb_name = "thumb/" . $this->file_prefix . $this->sess_id . ".". $ext; if($ext == "jpg" || $ext == "jpeg") { $thumb = imagecreatefromjpeg($upload_dir . $file_name); $thumbx = imagesx($thumb); $thumby = imagesy($thumb); if($mwidth <= 0 || $mwidth >= $thumbx) { $mwidth = $thumbx; } $mheight = ($thumbx*($mwidth/$thumbx)); if($thumbx > $thumby) { $width = $mwidth; $height = ($thumby*($mheight/$thumbx)); } if($thumbx < $thumby) { $width = ($thumbx*($mwidth/$thumby)); $height = $mheight; } if($thumbx == $thumby) { $width = $mwidht; $height = $mheight; } $thumbImg = imagecreatetruecolor($width, $height); imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby); imagejpeg($thumbImg, $upload_dir . $thumb_name, 100); imagedestroy($thumb); imagedestroy($thumbImg); } elseif ($ext == "png") { $thumb = imagecreatefrompng($upload_dir . $file_name); $thumbx = imagesx($thumb); $thumby = imagesy($thumb); if($mwidth <= 0 || $mwidth >= $thumbx) { $mwidth = $thumbx; } $mheight = ($thumbx*($mwidth/$thumbx)); if($thumbx > $thumby) { $width = $mwidth; $height = ($thumby*($mheight/$thumbx)); } if($thumbx < $thumby) { $width = ($thumbx*($mwidth/$thumby)); $height = $mheight; } if($thumbx == $thumby) { $width = $mwidht; $height = $mheight; } $thumbImg = imagecreatetruecolor($width, $height); imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby); imagejpeg($thumbImg, $upload_dir . $thumb_name, 100); imagedestroy($thumb); imagedestroy($thumbImg); } } function noValidation() { $temp_file_name = trim($this->temp_file_name); $file_name = $this->fileRename(); $upload_dir = $this->getUploadDir(); $upload_log_dir = $this->getUploadLogDir(); $file_size = $this->getFileSize(); $ip = trim($_SERVER['REMOTE_ADDR']); if($upload_dir == false || $upload_log_dir == false) { return false; } else { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; fwrite($fp, $this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />"); if($stat == true) { $this->createThumb(); } mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error()); return true; } else { return false; } } else { return false; } } } function fileValidation($stat) { $temp_file_name = trim($this->temp_file_name); $file_name = $this->fileRename(); $upload_dir = $this->getUploadDir(); $upload_log_dir = $this->getUploadLogDir(); $file_size = $this->getFileSize(); $ip = trim($_SERVER['REMOTE_ADDR']); $existing_file = $this->fileExist(); $valid_ext = $this->valExtension(); if($upload_dir == false || $upload_log_dir == false) { return false; } elseif ($existing_file == true ||$valid_ext == false) { return false; } else { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; fwrite($fp,$this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />"); if($stat == true) { $this->createThumb(); } mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error()); return true; } else { return false; } } else { return false; } } } } $upload = new upload; chmod("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam, 0777); $upload->temp_file_name = trim($_FILES['bestand']['tmp_name']); $upload->upload_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam; $upload->upload_log_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam."/logs"; $upload->file_prefix = "foto_"; $upload->thumb_width = 250; $upload->thumb_height = 150; $upload->ext_array = array(".jpg", ".jpeg", ".png"); $upload->sess_id = $naam; $uploadFile = $upload->fileValidation(true); } ?>
hij moet dus via een absolute path uploaden (maar dat doet hij dus niet :S, als ik gewoon web zou doen werkt het wel maar dan komt hij in n verkeerde map) dus nou zou ik willen weten hoe ik dat op kan lossen? hij maakt die dirs dus al niet aan. ziet iemand de fout?
|