Jump to content

unlink image


iNko

Recommended Posts

hi again, i have a image uploading page, i wanna add a delete option to each image that was uploaded..

 

the code that im using is taking thumbnails from folder, displaying only 4 images per page, and when u click on thumbnail - original sized image comes up, heres the code:


<?php
$del = "delete";
//The directory to your images folder, with trailing slash
$dir = "uploads/thumbs/watermarkedthumbs/";
$dir2 = "uploads/";
//Set the extensions you want to load, seperate by a comma.
$extensions = "jpeg,jpg,png,gif";
//Set the number of images you want to display per page
$imagesPerPage = 4;
//Set the $page variable
if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
//Load all images into an array
$images = glob($dir."*.{".$extensions."}", GLOB_BRACE);
$images2 = glob($dir2."*.{".$extensions."}", GLOB_BRACE);
//Count the number of images
$totalImages = count($images);
$totalImages2 = count($images2);
//Get the total pages
$totalPages = ceil($totalImages / $imagesPerPage);
$totalPages2 = ceil($totalImages2 / $imagesPerPage);
//Make sure the page you are on is not greater then the total pages available.
if($page > $totalPages){
//Set the currnet page to the total pages.
$page = $totalPages;
}
//Now find where to start the loading from
$from = ($page * $imagesPerPage) - $imagesPerPage;
//Now start looping
for($i = $from; $i < ($from + $imagesPerPage); $i++){
//We need to make sure that its within the range of totalImages.
if($i < $totalImages){
	//Now we can display the image!

 	  echo "<a href='{$images2[$i]}'><img style='border:thin solid
	  #FFF;margin-top:10px;margin-left:10px;margin-right:10px ' src='{$images[$i]}'alt='{$images[$i]}' /></a>";	
	 		  
}
}

//Now to display the page numbers!
for($p = 1; $p <= $totalPages; $p++){
if($p == $page){
	$tmp_pages[] = "<strong>{$p}</strong>";
}else{
	$tmp_pages[] = "<a href='?page={$p}'>{$p}</a>";
}
}
//Now display pages, seperated by a hyphon.
echo "<br/>" . implode(" - ", $tmp_pages);

?>

 

i was thinking of adding another echo here:

if($i < $totalImages){
	//Now we can display the image!

 	  echo "<a href='{$images2[$i]}'><img style='border:thin solid
	  #FFF;margin-top:10px;margin-left:10px;margin-right:10px ' src='{$images[$i]}'alt='{$images[$i]}' /></a>";	
	 		  
}

and then doing something with unlink..

 

do i need to look for something else to add a delete button to each image uploaded?

thx

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.