Click to See Complete Forum and Search --> : small error in code please help


markandkelle
10-23-2007, 09:11 AM
Hi, I really hope you can help as this is driving me insanse! I have a script that I am using and this part of the script deletes pictures.

function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = "../gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg'))
{
unlink($full.$image.'.jpg');
}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}


So now when I login to my page and select a photo to delete it comes up and says 1 or 2 or whatever photos deleted, but then I view the folder and they are still there?

The folder I am trying to delete the photos from is gallery, any ideas anyone?

thanks
Mark

stephan.gerlach
10-23-2007, 09:13 AM
not sure but you might have to work with


$_SERVER["DOCUMENT_ROOT"]

stephan.gerlach
10-23-2007, 09:14 AM
example



function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg'))
{
unlink($full.$image.'.jpg');
}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}

markandkelle
10-23-2007, 09:25 AM
Thanks for the reply I have changed it but still no joy, here is the resot of the code if it helps?

The delete section is highlighted red of what I changed from your advice


<?php

$user = 'username';
$pass = 'password';

session_start();

if(isset($_GET['log-out']))
{
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time()-86400, '/');
}
session_destroy();
header('Location: http://'.$_SERVER['HTTP_HOST'].htmlentities($_SERVER['PHP_SELF']));
die;
}
elseif(((!empty($_POST['user']) and !empty($_POST['pass']) and ereg($user.$pass, preg_replace('/\s/', '', trim($_POST['user']).trim($_POST['pass'])))) or (isset($_SESSION['logged']) and ($_SESSION['logged'] === true) and isset($_SESSION['user']) and ($_SESSION['user'] == $user))) and ($_SESSION['attempts'] < 5))
{
$_SESSION['logged'] = true;
$_SESSION['user'] = $user;
if(isset($_POST['user']))
{
header('Location: http://'.$_SERVER['HTTP_HOST'].htmlentities($_SERVER['PHP_SELF']));
}
}
else
{
top();
$_SESSION['attempts'] = isset($_SESSION['attempts']) ? ++$_SESSION['attempts'] : 0;
print '<form action="" method="post">
<p><label>Username: </label><input type="text" name="user"></p>
<p><label>Password: </label><input type="password" name="pass"></p>
<p><label>&nbsp</label><input type="submit" value="Enter"></p>
</form>';
bottom();
die;
}

top();

echo '<p><a href="'.htmlentities($_SERVER['PHP_SELF']).'?log-out">Log-out</a></p>';
if(count($_POST))echo '<p><a href="'.htmlentities($_SERVER['PHP_SELF']).'">Reset</a></p>';

if(isset($_POST['add_delete']) and (($_POST['add_delete'] == 'add') or ($_POST['add_delete'] == 'delete')))
{
$_SESSION['add_delete'] = $_POST['add_delete'];
if($_POST['add_delete'] == 'add')
{
add_form();
}
else
{
echo delete_form();
}
}
elseif(isset($_POST['step2']))
{
if($_SESSION['add_delete'] == 'add')
{
echo add_image('../gallery');
add_delete_form();
}
elseif($_SESSION['add_delete'] == 'delete')
{
echo delete_fotos();
add_delete_form();
}
}
else
{
add_delete_form();
}


bottom();

function top()
{
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="es">
<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<style type="text/css">
html, body{
margin:0;
padding:0.5em 2em;
font-size:1em;
}
form p label{
float:left;
width:8em;
padding-right:10px;
}

a{
color:#369;
text-decoration:none;
font-weight:bold;
}

a:hover{
color:#f63;
}

p{
clear:both;
}

p.text{
width:50%;
text-align:justify;
}

form.delete p{
float:left;
clear:none;
margin:0.5em;
}


span.warning{
color:#dd002b;
}

p label{
font-weight:bold;
}

.bold{
font-weight:bold;
}

.red{
font-weight:bold;
color:#f00;
}
</style>

<title>Admin</title>

</head>

<body>

<h2>Admin</h2>

<?php
}

function bottom()
{
?></body>

</html><?php
}


function add_delete_form()
{
?>
<form action="" method="post">
<p><label>Add photos</label> <input type="radio" name="add_delete" value="add" checked="checked"></p>
<p><label>Delete photos</label> <input type="radio" name="add_delete" value="delete"></p>
<p><label>Next step:</label> <input type="submit" name="submit" value="OK"></p>
</form>

<?php
}

function delete_form()
{
$dir = "../gallery/";

$content = null;

if(($count = count($glob = glob($dir."*.jpg"))) > 0)
{
foreach($glob as $v)
{
$filemtime[] = filemtime($v);
}
array_multisort($filemtime, SORT_DESC, $glob);
$content .= '<p>Check the box next to each photo you want to delete and then press &quot;Delete&quot;.</p>'."\n";
$content .= '<form action="" method="post" class="delete">'."\n";
foreach($glob as $file)
{
$content .= '<p><img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '', $file).'" alt=""><input type="checkbox" name="images[]" value="'.preg_replace('/\.jpg$/', '', substr($file, strlen($dir))).'"></p>'."\n";
}
$content .= '<p style="clear:both"><input type="submit" name="step2" value="Delete"></p>'."\n";
$content .= '</form>'."\n";
}
return $content;
}

function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg'))
{
unlink($full.$image.'.jpg');
}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}
function add_form()
{
?>
<p class="text">Use the form below to add images.</p>

<form action="upload.php" method="post" enctype="multipart/form-data">
<p><label>Photo</label> <input type="file" name="uploaded"></p>
<p><label>Next step</label> <input type="submit" value="upload"></p>
</form>

<?php

stephan.gerlach
10-23-2007, 09:30 AM
ok you need to do some debugging

after this line

$full = $_SERVER["DOCUMENT_ROOT"]."/gallery/";



add this one

echo 'path: '.$full.' <br />';


then you need to check and see if the path is correct. I assume not. correct it and it should work.

markandkelle
10-23-2007, 09:38 AM
Hi, thanks for your help, I really appreciate this, so you were right it was going to the wrong path, I have corrected this now and put the right path in, but its still not working?

any ideas?

stephan.gerlach
10-23-2007, 09:40 AM
ok put an echo before above the unlink line and see if it actually goes into that if condition

markandkelle
10-23-2007, 10:18 AM
Ok this is what I get

path: /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/
path: /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/

1 image deleted.

this is the code following your changes

function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
echo 'path: '.$full.' <br />';
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg')) echo 'path: '.$full.' <br />';
{
unlink($full.$image.'.jpg');
}
echo 'path: '.$full.' <br />';
}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}

stephan.gerlach
10-23-2007, 10:24 AM
ok it might then be a permission problem

put this line just above the unlink one



chmod($full.image.'.jpg', 0777);



hope this will work

markandkelle
10-23-2007, 10:36 AM
if(file_exists($full.image.'.jpg'))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
}
echo 'path: '.$full.' <br />';
}
}
}


Added this and still no joy?

stephan.gerlach
10-23-2007, 10:43 AM
oh i missed that you put that echo path thing at the wrong place. it has to be inside the if condition not after.

delete the unlink line and replace it with



echo 'DELETE IMAGE : '.$full.$image.'.jpg';


if you run it can you see that output?

markandkelle
10-23-2007, 10:54 AM
hi so i put the echo back in, at the right place, as you can prob tell I am not that bright with this :-)

so code now looks like this
function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
echo 'path: '.$full.' <br />';
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
echo 'path: '.$full.' <br />';

{
if(file_exists($full.image.'.jpg'))
echo 'path: '. full.' <br />';
{
chmod($full.image.'.jpg', 0777);
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}
And this is the result I get

path: /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/
path: /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/

Warning: chmod() [function.chmod]: No such file or directory in /home/ayoocouk/public_html/mysite.co.uk/inspiral/test/index.php on line 216
DELETE IMAGE : /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/3.jpg

markandkelle
10-23-2007, 10:56 AM
hmm, just realised the file name I am trying to delete is flower3.jpg but looking at this it is trying to delete a file named 3.jpg so its missing some of the name?

what do you think?

markandkelle
10-23-2007, 10:58 AM
just tried deleting another one and got this
DELETE IMAGE : /home/ayoocouk/public_html/mysite.co.uk/inspiral/gallery/.jpg

??

stephan.gerlach
10-23-2007, 11:00 AM
thats right the flower is part of the filename and is essential.

btw you copied the line again at the wrong place

it should be like this



function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
echo 'path: '.$full.' <br />';
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
echo 'path: '.$full.' <br />';

{
if(file_exists($full.image.'.jpg'))

{ echo 'path: '. full.' <br />';
chmod($full.image.'.jpg', 0777);
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}

markandkelle
10-23-2007, 11:04 AM
Thanks for that I have changed it now, so any idea how I get it to use the full file name and actually delete the pic?

markandkelle
10-23-2007, 12:13 PM
anyone know :-(

stephan.gerlach
10-23-2007, 01:58 PM
well where do you get the 3 from?

markandkelle
10-23-2007, 02:23 PM
no idea? sometimes it says a random number and other times it has nothing? just says /path/.jpg

?

stephan.gerlach
10-23-2007, 02:29 PM
ok how do you choose which image you want to delete?

markandkelle
10-23-2007, 03:47 PM
HI, so the script is a basic login and then when logged in you can upload jpg files to a specified folder or delete files, when you choose delete it then shows you every image in the folder with check boxes, you check the one you want to delete and then click delete.

rough example attached to help out hopefully

stephan.gerlach
10-24-2007, 03:10 AM
ok i see. the problem is the code that displays the images and the checkboxes. Can you show me the code?

markandkelle
10-24-2007, 04:18 AM
HI,
Thanks again for all your help, so here is the full code that I am using

<?php

$user = 'username';
$pass = 'password';

session_start();

if(isset($_GET['log-out']))
{
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time()-86400, '/');
}
session_destroy();
header('Location: http://'.$_SERVER['HTTP_HOST'].htmlentities($_SERVER['PHP_SELF']));
die;
}
elseif(((!empty($_POST['user']) and !empty($_POST['pass']) and ereg($user.$pass, preg_replace('/\s/', '', trim($_POST['user']).trim($_POST['pass'])))) or (isset($_SESSION['logged']) and ($_SESSION['logged'] === true) and isset($_SESSION['user']) and ($_SESSION['user'] == $user))) and ($_SESSION['attempts'] < 5))
{
$_SESSION['logged'] = true;
$_SESSION['user'] = $user;
if(isset($_POST['user']))
{
header('Location: http://'.$_SERVER['HTTP_HOST'].htmlentities($_SERVER['PHP_SELF']));
}
}
else
{
top();
$_SESSION['attempts'] = isset($_SESSION['attempts']) ? ++$_SESSION['attempts'] : 0;
print '<form action="" method="post">
<p><label>Username: </label><input type="text" name="user"></p>
<p><label>Password: </label><input type="password" name="pass"></p>
<p><label>&nbsp</label><input type="submit" value="Enter"></p>
</form>';
bottom();
die;
}

top();

echo '<p><a href="'.htmlentities($_SERVER['PHP_SELF']).'?log-out">Log-out</a></p>';
if(count($_POST))echo '<p><a href="'.htmlentities($_SERVER['PHP_SELF']).'">Reset</a></p>';

if(isset($_POST['add_delete']) and (($_POST['add_delete'] == 'add') or ($_POST['add_delete'] == 'delete')))
{
$_SESSION['add_delete'] = $_POST['add_delete'];
if($_POST['add_delete'] == 'add')
{
add_form();
}
else
{
echo delete_form();
}
}
elseif(isset($_POST['step2']))
{
if($_SESSION['add_delete'] == 'add')
{
echo add_image('../gallery');
add_delete_form();
}
elseif($_SESSION['add_delete'] == 'delete')
{
echo delete_fotos();
add_delete_form();
}
}
else
{
add_delete_form();
}


bottom();

function top()
{
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="es">
<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<style type="text/css">
html, body{
margin:0;
padding:0.5em 2em;
font-size:1em;
}
form p label{
float:left;
width:8em;
padding-right:10px;
}

a{
color:#369;
text-decoration:none;
font-weight:bold;
}

a:hover{
color:#f63;
}

p{
clear:both;
}

p.text{
width:50%;
text-align:justify;
}

form.delete p{
float:left;
clear:none;
margin:0.5em;
}


span.warning{
color:#dd002b;
}

p label{
font-weight:bold;
}

.bold{
font-weight:bold;
}

.red{
font-weight:bold;
color:#f00;
}
</style>

<title>Admin</title>

</head>

<body>

<h2>Admin</h2>

<?php
}

function bottom()
{
?></body>

</html><?php
}


function add_delete_form()
{
?>
<form action="" method="post">
<p><label>Add photos</label> <input type="radio" name="add_delete" value="add" checked="checked"></p>
<p><label>Delete photos</label> <input type="radio" name="add_delete" value="delete"></p>
<p><label>Next step:</label> <input type="submit" name="submit" value="OK"></p>
</form>

<?php
}

function delete_form()
{
$dir = "../gallery/";

$content = null;

if(($count = count($glob = glob($dir."*.jpg"))) > 0)
{
foreach($glob as $v)
{
$filemtime[] = filemtime($v);
}
array_multisort($filemtime, SORT_DESC, $glob);
$content .= '<p>Check the box next to each photo you want to delete and then press &quot;Delete&quot;.</p>'."\n";
$content .= '<form action="" method="post" class="delete">'."\n";
foreach($glob as $file)
{
$content .= '<p><img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '', $file).'" alt=""><input type="checkbox" name="images[]" value="'.preg_replace('/\.jpg$/', '', substr($file, strlen($dir))).'"></p>'."\n";
}
$content .= '<p style="clear:both"><input type="submit" name="step2" value="Delete"></p>'."\n";
$content .= '</form>'."\n";
}
return $content;
}

function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg'))
{
'DELETE IMAGE : '.$full.$image.'.jpg';
}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}
function add_form()
{
?>
<p class="text">Use the form below to add images.</p>

<form action="upload.php" method="post" enctype="multipart/form-data">
<p><label>Photo</label> <input type="file" name="uploaded"></p>
<p><label>Next step</label> <input type="submit" value="upload"></p>
</form>

<?php

stephan.gerlach
10-24-2007, 06:50 AM
ok what i would do is put some more debug echos into the code.

first i would above the line where you echo the image and the checkbox following line


$content .= 'FILE: '.$file.'<br />';


ok what does it say at the image flower3.jpg? does it say flower3.jpg or something different?

markandkelle
10-24-2007, 07:46 AM
Hi, so this is the code for the delete form that shows all pcs in the directory with checkbox to delete, where should I put the echo to debug?

function delete_form()
{
$dir = "../gallery/";

$content = null;

if(($count = count($glob = glob($dir."*.jpg"))) > 0)
{
foreach($glob as $v)
{
$filemtime[] = filemtime($v);
}
array_multisort($filemtime, SORT_DESC, $glob);
$content .= '<p>Check the box next to each photo you want to delete and then press &quot;Delete&quot;.</p>'."\n";
$content .= '<form action="" method="post" class="delete">'."\n";
foreach($glob as $file)
{
$content .= '<p><img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '', $file).'" alt=""><input type="checkbox" name="images[]" value="'.preg_replace('/\.jpg$/', '', substr($file, strlen($dir))).'"></p>'."\n";
}
$content .= '<p style="clear:both"><input type="submit" name="step2" value="Delete"></p>'."\n";
$content .= '</form>'."\n";
}
return $content;
}

stephan.gerlach
10-24-2007, 07:50 AM
function delete_form()
{
$dir = "../gallery/";

$content = null;

if(($count = count($glob = glob($dir."*.jpg"))) > 0)
{
foreach($glob as $v)
{
$filemtime[] = filemtime($v);
}
array_multisort($filemtime, SORT_DESC, $glob);
$content .= '<p>Check the box next to each photo you want to delete and then press &quot;Delete&quot;.</p>'."\n";
$content .= '<form action="" method="post" class="delete">'."\n";
foreach($glob as $file)
{
$content .= 'FILE: '.$file.'<br />';
$content .= '<p><img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '', $file).'" alt=""><input type="checkbox" name="images[]" value="'.preg_replace('/\.jpg$/', '', substr($file, strlen($dir))).'"></p>'."\n";
}
$content .= '<p style="clear:both"><input type="submit" name="step2" value="Delete"></p>'."\n";
$content .= '</form>'."\n";
}
return $content;
}

markandkelle
10-24-2007, 07:57 AM
Thanks for that, so it says ../gallery/flower3.jpg

which is the right file name, but when I click delete the echo says

1 file delted

../gallery/3.jpg

stephan.gerlach
10-24-2007, 08:06 AM
try this one


function delete_form()
{
$dir = "../gallery/";

$content = null;

if(($count = count($glob = glob($dir."*.jpg"))) > 0)
{
foreach($glob as $v)
{
$filemtime[] = filemtime($v);
}
array_multisort($filemtime, SORT_DESC, $glob);
$content .= '<p>Check the box next to each photo you want to delete and then press &quot;Delete&quot;.</p>'."\n";
$content .= '<form action="" method="post" class="delete">'."\n";
foreach($glob as $file)
{
$content .= 'FILE: '.$file.'<br />';
$parts = explode('/',$file);
$content .= '<p><img src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '', $file).'" alt=""><input type="checkbox" name="images[]" value="'.$parts[2].'"></p>'."\n";
}
$content .= '<p style="clear:both"><input type="submit" name="step2" value="Delete"></p>'."\n";
$content .= '</form>'."\n";
}
return $content;
}

markandkelle
10-24-2007, 08:13 AM
Ok, I have added that and there is no difference :-( also upon reading through the file names that are produced, some have no names at all it just says file:

stephan.gerlach
10-24-2007, 08:15 AM
ok

is that page online so I can have a look at it?

markandkelle
10-24-2007, 08:26 AM
yep,

the gallery is http://www.markandkelle.co.uk/inspiral/gallery.htm

the admin area is

http://www.markandkelle.co.uk/inspiral/test/index.php

username is username
password is password

globalwarming
10-24-2007, 08:30 AM
Your problem is very tricky but simple just remove = with == and everything else will work like a swiss watch.
if($count =

so replace it with if($count ==

stephan.gerlach
10-24-2007, 08:33 AM
you also removed the actual unlink command which should remove the files. Add that back in and it should work

globalwarming
10-24-2007, 08:33 AM
replace = with == for the first if statement

globalwarming
10-24-2007, 08:35 AM
Hi, I really hope you can help as this is driving me insanse! I have a script that I am using and this part of the script deletes pictures.

function delete_fotos()
{
if($count = count($_POST['images']))
{
$full = "../gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))
{
if(file_exists($full.image.'.jpg'))
{
unlink($full.$image.'.jpg');
}

}
}
}
return '<p>'.$count.' image'.(($count == 1)?'':'s').' deleted.</p>'."\n";
}


So now when I login to my page and select a photo to delete it comes up and says 1 or 2 or whatever photos deleted, but then I view the folder and they are still there?

The folder I am trying to delete the photos from is gallery, any ideas anyone?

thanks
Mark
remove = with == for the first if statement

stephan.gerlach
10-24-2007, 08:38 AM
globalwarming you posted that now 3 times. I think that should be enough now.

markandkelle
10-24-2007, 08:42 AM
ok so this is what the code now looks like

function delete_fotos()
{
if($count == count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{
if($image = preg_replace('/[^0-9]/', '', $image))


{
if(file_exists($full.image.'.jpg'))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}

}
}
}
return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}


and it is still not deleting the files, :-(

globalwarming
10-24-2007, 08:46 AM
if($image = must change to
if($image ==

stephan.gerlach
10-24-2007, 08:47 AM
what about this one?


function delete_fotos()
{
if($count == count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{

if(file_exists($full.image.'.jpg'))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}


}
}
return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}

globalwarming
10-24-2007, 08:48 AM
what about this one?


function delete_fotos()
{
if($count == count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{

if(file_exists($full.image.'.jpg'))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}


}
}
return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}



It should do the trick

stephan.gerlach
10-24-2007, 08:51 AM
:rolleyes:

markandkelle
10-24-2007, 08:57 AM
function delete_fotos()
{
if($count == count($_POST['images']))
{
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{

if(file_exists($full.image.'.jpg'))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image.'.jpg';

}


}
}
return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}



guess what? .......still not working :-(

stephan.gerlach
10-24-2007, 09:00 AM
ok this is my last try. if this won't work i give up. got plenty of other stuff to do as well





function delete_fotos()
{
$count = 0;
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{

if(file_exists($full.$image))

{
chmod($full.image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image;
$count++;
}


}

return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}



good luck.

globalwarming
10-24-2007, 09:03 AM
chmod($full.$image

should take you somewhere because you forgot to type the $ sign

markandkelle
10-24-2007, 09:20 AM
function delete_fotos()
{
$count = 0;
$full = $_SERVER["DOCUMENT_ROOT"]."/inspiral/gallery/";
foreach($_POST['images'] as $image)
{

if(file_exists($full.$image))

{
chmod($full.$image.'.jpg', 0777);
unlink($full.$image.'.jpg');
echo 'DELETE IMAGE : '.$full.$image;
$count++;
}


}

return '<p>'.$count.' image'.(($count = 1)?'':'s').' deleted.</p>'."\n";
}

still no good :-( all I need is some code to enable me to choose files in this folder and delete them, any other ideas on how I can do this?