Add a photo album and delete (edit)
Posted: Wed Dec 10, 2014 9:22 am
Hello,
I use this code when i want to add a picture, but now I need to edit and delete fixed(certain) pictures. How to change a code? For example I have 100 pics, and I want to delete 51 pictures and 49 remaining pictures
This is add_album.php
I use this code when i want to add a picture, but now I need to edit and delete fixed(certain) pictures. How to change a code? For example I have 100 pics, and I want to delete 51 pictures and 49 remaining pictures
This is add_album.php
Code: Select all
define("IMAGES_BIG_DIR", "../images/Big_images/");
define("IMAGES_SMALL_DIR", "../images/Small_images/");
define("IMAGE_HEIGHT", 180);
define("IMAGE_WIDTH", 210);
$allowed_type = array(
'image/jpeg',
'image/jpg',
'image/JPG',
'image/JPEG',
'image/pjpeg',
'image/x-png',
'image/png',
);
$allowed_ext = array('jpg', 'png', 'JPG', 'jpeg', 'JPEG');
if ( !empty($_FILES) ) {
//echo "<pre>";
//print_r($_POST);
//print_r($_FILES);
$number_of_images = isset($_FILES['images']['name']) ? count($_FILES['images']['name']) : 0;
if ( $number_of_images > 0 ) {
foreach ( $_FILES['images']['name'] as $nImagekey => $sImagaName ) {
if ( isset($_FILES['images']['error'][$nImagekey]) && $_FILES['images']['error'][$nImagekey] == UPLOAD_ERR_OK ) {
$extension = pathinfo($sImagaName, PATHINFO_EXTENSION);
if ( !in_array($_FILES['images']['type'][$nImagekey], $allowed_type) ) {
echo "Невалиден файлов формат!";
exit;
} else if ( !in_array($extension, $allowed_ext) ) {
echo "Невалиден файлов формат!";
exit;
}
$fn = sprintf(sha1_file($_FILES['images']['tmp_name'][$nImagekey]).'.%s', $extension);
$file_name = sprintf(IMAGES_BIG_DIR.'%s', $fn);
$file_name_sm = sprintf(IMAGES_SMALL_DIR.'%s', $fn);
$original_images_array[] = $file_name;
$small_images_array[] = $file_name_sm;
if ( !copy($_FILES['images']['tmp_name'][$nImagekey], $file_name) ) {
echo "Файла не може да бъде обработен.";
exit;
}
if ( strtolower($extension) == "jpg" ) {
$raw_img = imagecreatefromjpeg($file_name);
} else if ( strtolower($extension) == "png" ){
$raw_img = imagecreatefrompng($file_name);
}
if ( $raw_img ) {
$raw_x = imageSX($raw_img);
$raw_y = imageSY($raw_img);
if ($raw_x > $raw_y) {
$thumb_w = IMAGE_WIDTH;
$thumb_h = $raw_y * (IMAGE_HEIGHT / $raw_x);
} else if ($raw_x < $raw_y) {
$thumb_w = $raw_x * (IMAGE_HEIGHT / $raw_y);
$thumb_h = IMAGE_HEIGHT;
} else if ($raw_x == $raw_y) {
$thumb_w = IMAGE_WIDTH;
$thumb_h = IMAGE_HEIGHT;
}
$thumb = ImageCreateTrueColor($thumb_w, $thumb_h);
imagecopyresampled($thumb, $raw_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $raw_x, $raw_y);
if ( strtolower($extension) == "jpg" ) {
imagejpeg($thumb, $file_name_sm);
} else if ( strtolower($extension) == "png" ){
imagepng($thumb, $file_name_sm);
}
imagedestroy($thumb);
imagedestroy($raw_img);
}
}
}
}
} else if ( !empty($_POST) ) {
echo "Не сте избрали изображение. Задължително е да изберете поне едно";
exit;
}
$original_images_string = implode("|", $original_images_array);
$small_images_string = implode("|", $small_images_array);