aivanov Posted December 10, 2014 Share Posted December 10, 2014 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 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); Quote Link to comment https://forums.phpfreaks.com/topic/293007-add-a-photo-album-and-delete-edit/ Share on other sites More sharing options...
Psycho Posted December 10, 2014 Share Posted December 10, 2014 So, you want us to just write code to build all new functionality for you? This is not simply a matter to changing a few lines of code in that script. The functionality you are asking would require all new code. It is not "hard", but it is not trivial either. Quote Link to comment https://forums.phpfreaks.com/topic/293007-add-a-photo-album-and-delete-edit/#findComment-1499177 Share on other sites More sharing options...
aivanov Posted December 10, 2014 Author Share Posted December 10, 2014 (edited) This code multiple? Now you can upload more photos, but one by one <form action="#" method="post" enctype="multipart/form-data"> <div id="specifikacii"> <?php echo ' ?> </div> <div id="div_za_izbor_na_failove" > <h3><img src="images/camera-icon.png" />Добави изображения </h3> <table border="0" id="tabli4ka" ><tr><td> <input type="file" id="file_1" name="file_name_1" onchange="validaciq_na_izobrajeniqta()" multiple /> </td></tr></table> </div> <input type="hidden" id="hidden_value" value="1" name="number_of_images" /> <input type="hidden" id="pone_edno_izobr" value="no" name="at_least_one_pic" /> <input type="hidden" id="povtarqshti_se_izobrajeniq" value="no" name="povtarqshti_izobrajeniq" /> <input type="button" onclick="choose_another_file()" id="add_image" /></br> <input type="submit" value="Добави!" name="submitche" id="dobavi_zapis" disabled="disabled"> </form> <?php if(isset($_POST["submitche"])) { // vzimane na stoinostite ot tekstovite poleta $kategoriq = $_POST["kategorii"]; $marka = $_POST["marka"]; $model = $_POST["model"]; $godina_na_proizvodstvo = $_POST["godina_na_proizvodstvo"]; if($godina_na_proizvodstvo=="") { $godina_na_proizvodstvo ="NULL"; } else { $godina_na_proizvodstvo ="'$godina_na_proizvodstvo'"; } $dopulnitelna_informaciq = $_POST["tekstova_zona"]; if(empty($dopulnitelna_informaciq)) { $dopulnitelna_informaciq = "NULL" ; } else { $dopulnitelna_informaciq = "'$dopulnitelna_informaciq'" ; } $v_nalichnost = $_POST["available"]; // konekciq kum bazata danni $db = new MYSQL_DB(); $db->connect(); $db->select_db(); $db->set_names_utf_8(); $db->query="select * from advanced"; $db->run_query() ; $db->number_of_results_found_fn(); $namereni_rezultati = $db->number_of_results_found ; $id ; if($namereni_rezultati == 0) { $id = 1 ; } else { $db->query="SELECT COUNT(*) as total FROM advanced"; $db->run_query(); $db->number_of_results_found_fn() ; $rows = $db->number_of_results_found ; $row = mysql_fetch_array($db->query_result) ; $total_rows = $row[0]; $last_row_index = $total_rows - 1 ; $db->query="select Zapis_ID from advanced limit $last_row_index , 1 "; $db->run_query(); $row = mysql_fetch_array($db->query_result) ; $last_id_value = $row[0] ; $id = $last_id_value + 1 ; // da se testva } //echo "ID na posledniq red $id <br/>" ; // testov red $word = new Word_processing(); $model_trimmed = trim($model); $marka_trimmed = trim($marka); $name = $marka_trimmed."_".$model_trimmed."_id_".$id ; $word->name = $name ; $latin_name = $word->kirilica_kum_latinica(); //echo $latin_name."<br/>"; // testov red $number_of_images = $_POST['number_of_images']; // integer $number_of_real_images = 0 ; $at_least_one_pic = false ; for($i = 1 ; $i <= $number_of_images ; $i++) // proverka dali izobshto ima edno izobrano izobrajenie { $file_name = $_FILES["file_name_$i"]["name"]; if($file_name == "") { continue ; } else { $at_least_one_pic = true ; $number_of_real_images++ ; } } //echo " Nomer na poleta za kachvane na izobrajeniq : $number_of_images <br/>"; // testov red //echo "Nomer na realnite izobrajeniq $number_of_real_images <br/> "; $masiv = array(); // masiv sudurjash imenata na failove i tehnite razshireniq for($i = 1 ; $i <= $number_of_images ; $i++) { if($_FILES["file_name_$i"]["name"] == "") { continue ; } else { $masiv[] = $_FILES["file_name_$i"]["name"]; } } for($i = 0 ; $i < $number_of_real_images ; $i++) // proverka da nqma povtarqshti se izobrajeniq { for($z = 0 ; $z < $number_of_real_images ; $z++) { if($z == $i) { continue ; } else { if($masiv[$i]==$masiv[$z]) { echo "Не можеш да качиш две повтарящи се изображения ! Име на повтарящото се изображение : ".$masiv[$i]; exit ; } } } } if($at_least_one_pic == false) { echo "Не сте избрали изображение . Задължително е да изберете поне едно"; exit ; } else { $original_images_string ="" ; $small_images_string =""; $start = 1 ; $upload_folder_for_big_images="images/Big_images/"; $upload_folder_for_small_images="images/Small_images/"; // for cikul kopirash originalnoto izobrajenie i praveiki ot nego malko izobrajenie . Populva i gornite dva stringa i postavq sudurjanieto imm v baza danni kato referenciq // kum realnite izobrajeniq for($i = 1 ; $i <= $number_of_images ; $i++) { $file_name = $_FILES["file_name_$i"]["name"]; if($file_name == "") { continue ; } $extention = substr($file_name, -4) ; $path_plus_filename =$upload_folder_for_big_images.$latin_name."_pic_".$start.$extention ; $try_to_upload = move_uploaded_file($_FILES["file_name_$i"]["tmp_name"] , "../".$path_plus_filename); if($try_to_upload == false) { echo "problem pri uploada na source image !!!!"; exit ; } $original_images_string .= $path_plus_filename ; $original_images_string .="|"; resize_image("../".$path_plus_filename ,'210','180',$upload_folder_for_small_images.$latin_name."_pic_".$start.$extention ); $small_images_string .= $upload_folder_for_small_images.$latin_name."_pic_".$start.$extention ; $small_images_string .="|"; $start++; } } $original_images_string =substr($original_images_string ,0 ,-1 ) ; $small_images_string =substr($small_images_string , 0 , -1 ) ; $data = date("Y-m-d"); $db->query="INSERT INTO `shoemake_album`.`advanced` (`Zapis_ID`, `Kategoriq`, `Marka`, `Model`, `Godina_na_proizvodstvo`, `Dopulnitelna_informaciq`, `V_nalichnost`, `Big_images`, `Small_images`, `Data_na_dobavqne` , `Posledna_Redakciq`) VALUES (NULL, '$kategoriq', '$marka_trimmed', '$model_trimmed', $godina_na_proizvodstvo, $dopulnitelna_informaciq, '$v_nalichnost', '$original_images_string', '$small_images_string', '$data' , '$data' );"; //echo $db->query ; $db->run_query() ; $db->affected_rows(); if($db->number_of_affected_rows==1) { echo "Успешно добавихте запис за $marka_trimmed"; } else { echo "Проблем с добавянето на записа !"; } } ?> </div> </body> </html> Edited December 10, 2014 by aivanov Quote Link to comment https://forums.phpfreaks.com/topic/293007-add-a-photo-album-and-delete-edit/#findComment-1499179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.