Не мога да създам thumb изображения. Upload код:
<?php
include 'common.php';
if ($_SESSION['is_logged'] === true) {
if ($_FILES['user_pic']['tmp_name']) {
if ($_FILES['user_pic']['size'] > 2097152) {
$err[] = 'Файла е над 2mb';
}
if ($_FILES['user_pic']['type'] != 'image/gif' &&
$_FILES['user_pic']['type'] != 'image/jpeg' &&
$_FILES['user_pic']['type'] != 'image/pjpeg') {
$err[] = 'Файла не е снимка';
}
if (!$_POST['folder'] > 0) {
$err[] = 'Изберете папка';
}
if (count($err) == 0) {
if (!is_dir('user_pics' . DIRECTORY_SEPARATOR . $_SESSION['user_id'])) {
mkdir('user_pics' . DIRECTORY_SEPARATOR . $_SESSION['user_id']);
}
$name = time() . '_' . $_FILES['user_pic']['name'];
if (move_uploaded_file($_FILES['user_pic']['tmp_name'], 'user_pics'.DIRECTORY_SEPARATOR.$_SESSION['user_id'].DIRECTORY_SEPARATOR.$name)) {
if($_POST['is_public']==1)
{
$public=1;
}
else
{
$public=0;
}
run_q('INSERT INTO pictures (pic_name,catalogie_id,comment,date_added,is_public) VALUES ("'.$name.'",'.(int)$_POST['folder'].',"'.addslashes($_POST['user_desc']).'",'.time().','.$public.')');
create_thumb('user_pics'.DIRECTORY_SEPARATOR.$_SESSION['user_id'].DIRECTORY_SEPARATOR.$name);
$succes = true;
} else {
$err[] = 'Грешка при копиране на файла. Моля опитайте отново';
}
}
}
$folders = fetch_all(run_q('SELECT * FROM user_catalogs WHERE user_id=' . $_SESSION['user_id']));
include 'templates/header.php';
include 'templates/upload.php';
include 'templates/footer.php';
} else {
header('Location: index.php');
exit;
}
function create_thumb($source,$thumb_width=100)
{
$fl=dirname($source);
$new_name='thumb_'.basename($source);
$img = imagecreatefromjpeg($source);
$width = imagesx($image);
$height = imagesy($image);
$new_width = $thumb_width;
$new_height = floor( $height * ( $thumb_width / $width ) );
$tmp_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresized( $tap_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg( $tap_img, $fl.DIRECTORY_SEPARATOR.$new_name);
}
?>