0

Hi i am new in this website and i hope i have fun with all the members here,
I am trying to make code that get all the names of the files from folder and beside each one link to delete it
This is the code i have done but dunno why not working

The Full Code:

<?php
if($_GET['do'] == 'delete')
{
     unlink($myFile);
}

$myFile = $files[$i];
$collection = "";
$files = glob("gallery/*.*");
for
 ($i=0; $i<count($files); $i++) { $collection = $collection."\"".$files[$i]."\"".",". '<a href="index.php?do=delete">Delete file</a>.';}
 echo $collection;
 
 ?>

This part get the files names from the folder "gallery/" and post it:{And its working Perfect

<?php
$collection = "";
$files = glob("gallery/*.*");
for
 ($i=0; $i<count($files); $i++) { $collection = $collection."\"".$files[$i]."\"<br />";}
 echo $collection;
 
 ?>

This Part Which Delete the file (And its working perfect alone)
The Full Code:

<?php
if($_GET['do'] == 'delete')
{
     unlink($myFile);
}

$myFile = "Name Of The File";
?>
<a href="index.php?do=delete">Delete file</a>

But now i want him Automatic get the name of the file i want him to delete
when i try to change the "Name Of The File" with

<?php $myFile = $files[$i]; ?>

Not Working :/
So how i make him get the Name Of The File I Want To Delete?

2
Contributors
8
Replies
10
Views
7 Years
Discussion Span
Last Post by rajarajan07
0
<?php
if($_GET['do'] == 'delete')
{
	$myFile = $files[$_GET['id']];
	echo $myFile;
    unlink($myFile);
}

$collection = "";
$files = glob("gallery/*.*");
for ($i = 0; $i < count($files); $i++)
{ 
$collection = $collection."\"".$files[$i]."\"".",". "<a href=\"test.php?do=delete&id='$i'\">Delete file</a>";
}
echo $collection;
?>
0

Nah Not Working :(
maby i have to make it 777 permission?

Edited by DarkBerzerk™: n/a

1
<?php
if($_GET['do'] == 'delete')
{
	$myFile = $_GET['param'];
	$myFile=trim($myFile) ;
	unlink($myFile);
}

$collection = "";
$files = glob("d:\gallery\*.*");
for ($i = 0; $i < count($files); $i++)
{ 
echo "<br/>";
$param = $files[$i];
$collection = $collection."\"".$files[$i]."\"".",". "<a href=\"test.php?do=delete&param='$param'\">Delete file</a>";
}
echo $collection;
?>
Votes + Comments
Thanks Too Much For Trying Hard To Help Me
0

Didnt work and didnt even show the file names...
But after i changed the

$files = glob("d:\gallery\*.*");

To:

$files = glob("gallery/*.*");

he display the files names but dont delete when i press

0

BTW when i want to delete special file it workx:

<?php
if($_GET['do'] == 'delete')
{
	/*$myFile = $files[$_GET['id']];*/
	$myFile = "gallery/Untitled-1.jpg";
    unlink($myFile);
}
 
$collection = "";
$files = glob("gallery/*.*");
for ($i = 0; $i < count($files); $i++)
{ 
$collection = $collection."\"".$files[$i]."\"".",". "<a href=\"test.php?do=delete&id='$i'\">Delete file</a>";
}
echo $collection;
?>
0

WOHOOOOOOOOOOOOOOOOOOOOOO WORKING :D i made some changes and its working :D i removed the $param' in the link with $param (removed the ' ' ) and the folder location and its working WOW :D

The Final Code:

<?php
if($_GET['do'] == 'delete')
{
	$myFile = $_GET['param'];
	$myFile=trim($myFile) ;
	unlink($myFile);
}
 
$collection = "";
$files = glob("gallery/*.*");
for ($i = 0; $i < count($files); $i++)
{ 
$param = $files[$i];
$collection = $collection."\"".$files[$i]."\"".",". "<a href=\"index.php?do=delete&param=$param\">Delete file</a>";
}
echo $collection;
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.