PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
aivanov
Forum Newbie
Posts: 3 Joined: Wed Dec 10, 2014 9:15 am
Post
by aivanov » 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
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);
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Dec 10, 2014 3:11 pm
Doesn't look like there's anything to change there. That code is just for uploading. You need new code somewhere else for editing and for deleting.
aivanov
Forum Newbie
Posts: 3 Joined: Wed Dec 10, 2014 9:15 am
Post
by aivanov » Wed Dec 10, 2014 3:59 pm
I just need to delete photos
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Dec 10, 2014 4:17 pm
Yes, I know. You said that in your first post. But that doesn't change the fact that the code you've posted is, while relevant, not where the new code needs to go.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Dec 10, 2014 5:11 pm
aivanov wrote: 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
How do you want to select the images to delete? Checkboxes?
(#10850)
aivanov
Forum Newbie
Posts: 3 Joined: Wed Dec 10, 2014 9:15 am
Post
by aivanov » Thu Dec 11, 2014 7:17 am
This is the page album_edit.php
Code: Select all
<script type="text/javascript">
function delete_image(nomer)
{
idd = document.getElementById("skritoto_id").value;
t = confirm("Сигурни ли сте че искате да изтрите изображението ???");
if(t==false)
{
return ;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("delete_image").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","delete_only_one_image_advanced.php?image_numb="+nomer+"&id="+idd,true);
xmlhttp.send();
//window.location ='album_edit_item.php?id='+idd;
//location.reload(true)
// izpulnqvat se mn burzo i zatova nqma vreme da se izvika AJAX -> delete_only_one_image.php?image_numb
x=document.getElementById("tqloto");
x.style.visibility="hidden";
y= document.getElementById("rezultat");
y.style.visibility="visible";
countdown_refresh_same_page(5 , idd , 'Успешно изтрихте изображение свързано с запис');
}
function go_previous(numb)
{
max_izobr = document.getElementById("kolko_izobrajeniq_sa").value;
minus_one = numb - 1 ;
// vzimane na stoinosti ot skritite tekstovi poleta
small_img_current = document.getElementById("sml_img_"+numb).value;
big_img_current = document.getElementById("bg_img_"+numb).value;
small_img_previous =document.getElementById("sml_img_"+minus_one).value;
big_img_previous =document.getElementById("bg_img_"+minus_one).value;
// deal with previous container (Left located)
document.getElementById("tiny_img_"+minus_one).innerHTML = '<img src="../images/'+small_img_current+'">';
if(minus_one!=1)
{
document.getElementById("tiny_img_"+minus_one).innerHTML+='<a href="" onclick="go_previous('+minus_one+');return false;"><img src="images/Actions-go-previous-icon.png" border="0"></a>';
}
document.getElementById("tiny_img_"+minus_one).innerHTML+='<a href="#" onclick="delete_image('+minus_one+')"><img src="images/camera-delete-icon.png" border="0"></a>';
document.getElementById("tiny_img_"+minus_one).innerHTML+='<a href="" onclick="go_next('+minus_one+');return false;"><img src="images/Actions-go-next-icon.png" border="0"></a>';
// deal with cointainer calling this function
document.getElementById("tiny_img_"+numb).innerHTML ='<img src="../images/'+small_img_previous+'">';
if(numb!=1)
{
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="" onclick="go_previous('+numb+');return false;"><img src="images/Actions-go-previous-icon.png" border="0"></a>';
}
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="#" onclick="delete_image('+numb+')"><img src="images/camera-delete-icon.png" border="0"></a>';
if(numb!=max_izobr)
{
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="" onclick="go_next('+numb+');return false;"><img src="images/Actions-go-next-icon.png" border="0"></a>';
}
// razmqna na stoinostite na skritite tekstovi poleta
document.getElementById("bg_img_"+numb).value= big_img_previous;
document.getElementById("sml_img_"+numb).value= small_img_previous;
document.getElementById("bg_img_"+minus_one).value= big_img_current;
document.getElementById("sml_img_"+minus_one).value= small_img_current;
}
function go_next(numb)
{
// num 3 for example
max_izobr = document.getElementById("kolko_izobrajeniq_sa").value; // 4
plus_one = numb + 1 ;
// deal with next container (right located)
small_img_current = document.getElementById("sml_img_"+numb).value; // sml_img_3
big_img_current = document.getElementById("bg_img_"+numb).value; // bg_img_3
small_img_next =document.getElementById("sml_img_"+plus_one).value; // sml_img_4
big_img_next =document.getElementById("bg_img_"+plus_one).value; // sml_img_4
document.getElementById("tiny_img_"+plus_one).innerHTML = '<img src="../images/'+small_img_current+'">'; //tiny_img_4.innerHTML = sml_img_3
document.getElementById("tiny_img_"+plus_one).innerHTML+='<a href="" onclick="go_previous('+plus_one+');return false;"><img src="images/Actions-go-previous-icon.png" border="0"></a>';
// tiny_img_4.innerHTML+= go_previous(4)
document.getElementById("tiny_img_"+plus_one).innerHTML+='<a href="#" onclick="delete_image('+plus_one+')"><img src="images/camera-delete-icon.png" border="0"></a>';
if(max_izobr!= plus_one)
{
document.getElementById("tiny_img_"+plus_one).innerHTML+='<a href="" onclick="go_next('+plus_one+');return false;"><img src="images/Actions-go-next-icon.png" border="0"></a>';
// // tiny_img_4.innerHTML+= go_next(4)
}
document.getElementById("bg_img_"+plus_one).value= big_img_current;
document.getElementById("sml_img_"+plus_one).value= small_img_current;
// deal with cointainer calling this function
document.getElementById("tiny_img_"+numb).innerHTML ='<img src="../images/'+small_img_next+'">';
if(numb!=1)
{
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="" onclick="go_previous('+numb+');return false;"><img src="images/Actions-go-previous-icon.png" border="0"></a>';
}
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="#" onclick="delete_image('+numb+')"><img src="images/camera-delete-icon.png" border="0"></a>';
document.getElementById("tiny_img_"+numb).innerHTML+='<a href="" onclick="go_next('+numb+');return false;"><img src="images/Actions-go-next-icon.png" border="0"></a>';
document.getElementById("bg_img_"+numb).value= big_img_next;
document.getElementById("sml_img_"+numb).value= small_img_next;
}
</script>
<?php
for($i = 0, $k=1 ; $i < $total_images ; $i++ , $k++)
{
echo'<input type="hidden" value="'.$small_images_masiv[$i].'" id="sml_img_'.$k.'" name="sml_imagees_'.$k.'">';
echo'<input type="hidden" value="'.$big_images_masiv[$i].'" id="bg_img_'.$k.'" name="bg_imagees_'.$k.'">';
}
?>
<div class="kytiq_snimki">
<div class="iztrii_premesti">Изтрий/Премести изображение</div>
<?php
for($i = 0, $one = 1 ; $i < $total_images ; $i++ , $one++)
{
echo '<div id="tiny_img_'.$one.'">';
echo '<img src="../images/'.$small_images_masiv[$i].'">';
if($i!=0 )
{
echo '<a href="" onclick="go_previous('.$one.');return false;"><img src="images/Actions-go-previous-icon.png" border="0"></a>';
}
echo '<a href="" onclick="delete_image('.$one.');return false;"><img src="images/camera-delete-icon.png" border="0"></a>';
if($i !=($total_images - 1))
{
echo '<a href="" onclick="go_next('.$one.');return false;"><img src="images/Actions-go-next-icon.png" border="0"></a>';
}
echo '</div>';
}
?>
This is the page album_delete.php
Code: Select all
$new_query_for_small_images="";
$new_query_for_big_images="";
for($i = 0 ; $i < $obsht_broi_izobr ; $i++ )
{
if($i == $number_for_array)
{
// delete
//echo "za iztrivane :"."../".$masiv_big_images[$i];
//echo "za iztrivane :"."../".$masiv_small_images[$i];
unlink("../images/".$masiv_small_images[$i]) ;
unlink("../images/".$masiv_big_images[$i]) ;
$i++;
for($i ; $i < $obsht_broi_izobr ; $i++ )
{
// echo "<br>";
// preimenuvane na golemite izobrajeniq
// echo "<br>";
//echo "Преименуване на големите изображения !!!";
$razshirenie = substr($masiv_big_images[$i] , -4) ;
$to_dot = substr($masiv_big_images[$i] , 0 , $chislo ) ;
//namirane na poziciqta na '_pic'
$do_poslednata_dolna_cherta = substr($masiv_big_images[$i], 0 , $poslednata_dolna_cherta +1) ;
$nomer = substr($to_dot , $poslednata_dolna_cherta + 1 ) ;
// echo "<br>";
$sglobqvane_na_ime_big = "$do_poslednata_dolna_cherta$i$razshirenie";
rename("../images/Big_images/".$masiv_big_images[$i], "../images/$do_poslednata_dolna_cherta$i$razshirenie");
// echo "../".$masiv_big_images[$i];echo "<br>";
//echo "../$do_poslednata_dolna_cherta$i$razshirenie";
//echo "<br>";
//preimenuvane na malkite izobrajeniq
//echo "Преименуване на малките изображения !!!";
//
//echo "<br>";
$razshirenie = substr($masiv_small_images[$i] , -4) ;
$to_dot = substr($masiv_small_images[$i] , 0 , $chislo ) ;
//namirane na poziciqta na '_pic'
$do_poslednata_dolna_cherta = substr($masiv_small_images[$i], 0 , $poslednata_dolna_cherta +1) ;
$nomer = substr($to_dot , $poslednata_dolna_cherta + 1 ) ;
$sglobqvane_na_ime_small ="$do_poslednata_dolna_cherta$i$razshirenie";
rename("../images/Small_images/".$masiv_small_images[$i], "../images/$do_poslednata_dolna_cherta$i$razshirenie");
//echo "../".$masiv_small_images[$i] ;
//echo "<br>";
//echo "../$do_poslednata_dolna_cherta$i$razshirenie";
//echo "<br>";
$new_query_for_big_images.=$sglobqvane_na_ime_big;
$new_query_for_big_images.="|";
$new_query_for_small_images.=$sglobqvane_na_ime_small;
$new_query_for_small_images.="|";
//echo "zaqvka za golemite izobr : $new_query_for_big_images";
// "<br>";
//echo "zaqvka za malkite izobr : $new_query_for_small_images";
//echo "<br>";
}
break ;
}
else
{
$new_query_for_big_images.=$masiv_big_images[$i];
$new_query_for_big_images.="|";
$new_query_for_small_images.=$masiv_small_images[$i];
$new_query_for_small_images.="|";
}
}
$new_query_for_big_images = substr($new_query_for_big_images , 0 , -1 );
$new_query_for_small_images = substr($new_query_for_small_images , 0 , -1 );