<?php
session_start();
$max_file=10;
if ($_POST['upload_file']) {
$upload_dir='upload_file';
$tum_folder=$upload_dir.'/tumb';
$maxFilet=(int)$_POST['cnt_file'];
for ($counFilet = 1 ; $counFilet <=$maxFilet; $counFilet++) {
if (!$_FILES['file'.$counFilet]['tmp_name']) {
$_SESSION['error_niama'][$counFilet]="NIAMA ZAKACHENI FAJLOVE";
} else {
if ($_FILES['file'.$counFilet]['size'] > 4194304) {
$_SESSION['error_goliama'][$counFilet] = "SNIMKATA E MNOGO GOLIAMA ";
}
if (!(($_FILES['file'.$counFilet]['type'] == 'image/gif')
|| ($_FILES['file'.$counFilet]['type'] == 'image/jpeg'))) {
$_SESSION['error_ne'][$counFilet] = "FAILAT NE E SNIMKA ";
}
if (!(is_dir($upload_dir))) {
mkdir($upload_dir);
}
if (!(is_dir($tum_folder))) {
mkdir($tum_folder);
}
if (count($_SESSION['error_ne']==0) and count($_SESSION['error_goliama']==0)) {
$tmp_name = $_FILES['file'.$counFilet]["tmp_name"];
$name = time() . '_' . $_FILES['file'.$counFilet]["name"];
$fsize = $_FILES['file'.$counFilet]["size"];
if (move_uploaded_file($tmp_name, $upload_dir .'/'. $name)) {
create_tumb($upload_dir .'/'. $name,$counFilet);
$succes = TRUE;
} else {
$_SESSION['error_fatal'][$counFilet] = "GRESHKA PRI KOPIRANE NA FAILA1";
}
}
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<center>
Файловете да не са по големи от 4 МБ.
<hr>
<div id="up_form" style="width:330px;">
<form name="up_mor1_file" method="POST" enctype="multipart/form-data">
<?php
for ($cnt_file = 1 ; $cnt_file <=$max_file ; $cnt_file++) {
?>
Избври файл : <input type="file" name="file<?php echo $cnt_file; ?>" value="" width="200" />
<div style="width:330px;"><?php echo $_SESSION['error_goliama'][$cnt_file]; ?></div>
<div style="width:330px;"><?php echo $_SESSION['error_ne'][$cnt_file]; ?></div>
<div style="width:330px;"><?php echo $_SESSION['error_fatal'][$cnt_file]; ?></div>
<div style="width:330px;"><?php echo $_SESSION['error_niama'][$cnt_file]; ?></div>
<?php
}
?>
<hr>
<input type="submit" value="КАЧИ ФАЙЛОВЕТЕ" name="upload_file" />
<input type="hidden" value="10" name="cnt_file" />
</form>
</div>
</center>
</body>
</html>
<?php
function create_tumb($sourse, $counFilet,$tumb_width=196) {
if (($_FILES['file'.$counFilet]['type'] == 'image/gif')) {
$tum_folder = dirname($sourse);
$new_name = 'tumb_' . basename($sourse);
$img = imagecreatefromgif($sourse);
$width = imagesx($img);
$height = imagesy($img);
if ($width > $height) {
$new_width = floor($width * ( $new_height / $height ));
$new_height = $tumb_width;
} else {
$new_width = $tumb_width;
$new_height = floor($height * ( $tumb_width / $width ));
}
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($tmp_img, $tum_folder .'/'. $new_name);
}
if (($_FILES['file'.$counFilet]['type'] == 'image/bmp')) {
$tum_folder = dirname($sourse);
$new_name = 'tumb_' . basename($sourse);
$img = imagecreatefromjpeg($sourse);
$width = imagesx($img);
$height = imagesy($img);
$new_width = $tumb_width;
$new_height = floor($height * ( $tumb_width / $width ));
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($tmp_img, $tum_folder .'/'. $new_name);
}
if (($_FILES['file'.$counFilet]['type'] == 'image/jpeg')) {
$tum_folder = dirname($sourse);
$new_name = 'tumb_' . basename($sourse);
$img = imagecreatefromjpeg($sourse);
$width = imagesx($img);
$height = imagesy($img);
$new_width = 300;
$new_height = floor($height * ( 300 / $width ));
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($tmp_img, $tum_folder .'/'. $new_name);
}
if (($_FILES['file'.$counFilet]['type'] == 'image/png')) {
$tum_folder = dirname($sourse);
$new_name = 'tumb_' . basename($sourse);
$img = imagecreatefrompng($sourse);
$width = imagesx($img);
$height = imagesy($img);
if ($width > $height) {
$new_width = floor($width * ( $new_height / $height ));
$new_height = $tumb_width;
} else {
$new_width = $tumb_width;
$new_height = floor($height * ( $tumb_width / $width ));
}
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($tmp_img, $tum_folder .'/'. $new_name);
}
}
session_destroy();