MiniMonty Posted November 12, 2009 Share Posted November 12, 2009 Hi all, First the set up: Each user has a numbered dir. Inside is a dir "images" and inside that a dir "thumbs". Users upload images to their "images" dir. A file path is recorded in the db. Now the question... I have a script that will display take all the images uploaded by any given user, make a thumbnail copy of each one in "thumbs" then display the thumbnails in a table. Each image has a checkbox beneath it. At the top of the page is a submit button "Delete" It goes like this: <?php session_start(); if(isset($_GET['id']) || isset($_POST['id'])); else if (isset($_SESSION['id'])) { $id = $_SESSION['id']; } else { include_once "register.php"; exit(); } include_once "scripts/connect_to_mysql.php"; $deleteMsg= "Your image was successfully delted"; $id = $_SESSION['id']; ob_start(); $dir = opendir( "members/$id/images" ); $pics = array(); while( $fname = readdir( $dir ) ) { if ( preg_match( "/[.]jpg$/", $fname ) ) $pics []= $fname; } closedir( $dir ); foreach( $pics as $fname ) { $im = imagecreatefromjpeg( "members/$id/images/$fname" ); $ox = imagesx( $im ); $oy = imagesy( $im ); $nx = 100; $ny = floor( $oy * ( 100 / $ox ) ); $nm = imagecreatetruecolor( $nx, $ny ); imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy ); imagejpeg( $nm, "members/$id/images/thumbs/$fname" ); } ?> <html> <head><title>Manage Images</title> <link href="../../../../styles/main.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style1 {font-size: 12px} --> </style> </head> <body> <?php include_once "header_template3.php"; ?> <br> <br> <br> <div align="left"><br> </div> <form name="form1" method="post" action="manage_images.php"> <table width="80%" border="0" align="center"> <tr> <td><div align="center" class="Times19">Check the box for each image you want to permanently delete then click <input type="submit" name="Submit" value="Delete"> </div></td> </tr> <tr> <td> </td> </tr> <tr> <td> <table width="500" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF"> <tr> <?php $index = 0; foreach( $pics as $fname ) { ?> <td valign="middle" align="center"> <a href="../<?php echo( $fname ); ?>"><img src="<?php echo( $fname );?>" border="2" class="orangeText" /></a> <br> <input type="checkbox" name="delete_pictures[]" value="$fname" /></td> <?php $index += 1; if ( $index % 7 == 0 ) { echo( "</tr><tr>" ); } } ?> </tr> </table></td> </tr> </table> </form> <br> <?php include_once "footer_template.php"; ?> </body> </html> <?php $html = ob_get_clean(); $fh = fopen( "members/$id/images/thumbs/display.php", "w" ); fwrite( $fh, $html ); fclose( $fh ); header("Location: members/$id/images/thumbs/display.php"); ob_end_flush(); ?> What I want to acheive is for users to check all the images they want to delete, click the button and presto ! Image deleted from "images", thumb deleted form "thumbs" and record deleted from the db. I've tried quite a few ways but no joy so all and any help on this much appreciated. Best wishes Monty Link to comment https://forums.phpfreaks.com/topic/181243-deleting-images/ Share on other sites More sharing options...
Garethp Posted November 12, 2009 Share Posted November 12, 2009 Deleting filed is done by unlink($Filepath); If that doesn't work, put this before it chmod($Filepath, '0777'); Link to comment https://forums.phpfreaks.com/topic/181243-deleting-images/#findComment-956151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.