Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 06-12-2013, 02:36 PM   #1
Join Date: May 2013
Posts: 3
Default deleting files

hi guys... need help...

i have got pretty much all of a site up and running. i am uploading multiple files to a created folder for each record and its all going well the relevant code for the file uploads is

  	 	 $dirname = $_POST["stockID"];
	 $filename = "../images/cars/" . $dirname . "/";

if (!file_exists($filename)) {
    mkdir("../images/cars/" . $dirname, 0777);
} else {
    die( '<div class="error"> "The directory" . $dirname . "exists."</div>
	<div><button onclick="history.go(-1);">Back </button></div>' );

if (isset($_FILES['pix']) === true) {
		$files = $_FILES['pix'];
		for($x = 0; $x < count($files['name']); $x++) {
	$errors = array();
	$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
	$file_name = $files['name'][$x];
	$file_ext = strtolower(end(explode('.', $file_name)));
	$file_size = $files['size'][$x];
	$file_tmp = $files['tmp_name'][$x];
	if (in_array($file_ext, $allowed_ext) === false) {
		$errors[] = 'Extension not allowed';
	if ($file_size > 4097152) {
		$errors[] = 'File size must be under 2mb';
	if (empty($errors)) {
	if (move_uploaded_file($file_tmp, "../images/cars/" . $dirname . "/" . $file_name)); 
	} else {
		foreach ($errors as $error) {
			echo $error, '<br />';
HTML form
    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1">
        <label for="pix[]">Choose files to upload:</label>
        <input type="file" name="pix[]" id="pix[]" multiple />
        <input type="submit" name="insert" id="insert" value="Add to stock"></p>
my big question is, whilst the folders contain random amounts of images, with the usual type of image names and the directories using the Primary key to name, i cannot delete them when i delete a record. tried using
$dir = '../images/cars/' . $row_getStock["stockID"];
foreach(glob('../images/cars' . $row_getStock["stockID"] . '/*.jpg') as $file) {

rmdir ($dir);
with no joy at all..i just want to click the delete record link and it all happen am i asking too much

any ideas?

honda-mini is offline   Reply With Quote
Old 06-13-2013, 02:53 AM   #2
edbr's Avatar
Join Date: Aug 2005
Location: Bali
Posts: 11,176

i can only think the returned path is not correct.

i dont see where you inset the file name into your database, that would create the correct path.
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 06-13-2013, 08:41 AM   #3
Join Date: May 2013
Posts: 3

My mistake.. I should have clarified more

There is no correlation to the database for the image files, other than using the primary key to name the directory, as I'm using über gallery to handle the thumbnail creation on the fly, so to speak... Just pointing it at 'images/cars/' . $someVariable . '/', as the amount of images uploaded could vary from one upwards so didn't want to get into something like if there's 20 images and only 6 fields, write and name another 14 fields (columns?) to accommodate

As this is essentially my first dive into PHP I didn't know what the standard was so went with my gut. It's taken quite a few weeks for this simple(ish) site because at every point I've looked at tutorials and if I've d/l'd code to use, I've studied it to see if I can find out how it does what it does I do have to say though... Some of the stuff dreamweaver inserts automatically has me struggling lol

So, essentially all I want to do is,say, if I have a folder structure of

Then after that the variable named folders that tie to the record entries, with each folder containing a variable amount of files

What I want to do is when I delete, say, record number 6 (which is happen ending fine btw) I also want to delete folder at images/cars/6/ and all files inside that directory which could be 1- whatever depending on his uploading lol

So I need a script that will upon submitting the delete record, look how many files are in said folder, delete them and folder... Simple huh lol

Now it can either do the deleting on submit, or even another page to show the files graphically like an FTP page but not as my friend is totally not web friendly

This lot may or may not have clarified

honda-mini is offline   Reply With Quote
Old 07-04-2013, 05:39 AM   #4
Join Date: Dec 2010
Posts: 366

you will note that .. may not necessarily refer to your web directory. it could refer to your home directory. why not verify that by doing
echo getcwd();
note that this may not work, it may return false if PHP isn't configured to work with it. read up on it first in the php docs.
current working directory.
you could also replace your .. with
THAT you can echo with no problems, it always works. be sure to see what it actually is. it could be be your web directory. also note that its value may change over time, so don't try using a canned value.
Jim Michaels
HTML Code:
browser confusion (I believe the term is 'tag soup')!

Last edited by jmichae3; 07-04-2013 at 05:45 AM..
jmichae3 is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:20 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com