Button to Delete file (unlink)
Discuss coding issues, and scripts related to PHP and MySQL.
-
JanMolendijk
- Posts: 268
- Location: Holland Rotterdam
Button to Delete file (unlink)
I`m back again this time with an question for unlink
i lookt for 6 hours for an solution to delete pictures placed into this code
Code: Select all
<?php
$files = glob("../images/$users[email]/*.*");
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
echo '<div class="col-xs-6 col-md-3">
<div class="thumbnail">
<a href="'.$num.'" rel="shadowbox"><img src="'.$num.'" class="img-responsive" style="width:200px;height:150px;"> </a>
<br>
<div class="caption">
<p>Code for Notice<br><input type="text" class="form-control" value="<img src='. str_replace("..","http://145.53.93.209/Comments/","$num").' class=img-responsive></img> "></p>
</div></div>
</div>
</div>';
}
?>
How can i make an button to delete pictures i cant find out ?
Admin
Hello,
Try adapt this code to your script:
Code: Select all
//get the files into an array
$files = glob('../images/'. $users['email'] .'/*.*');
$nrf = count($files);
$reout =''; //store data to output
//traverse the array, add form with button to delete it
for($i=0; $i<$nrf; $i++){
$reout .='<form action="delfile.php" method="post"><input type="hidden" name="delf" value="'. urlencode($files[$i]) .'" /><input type="submit" value="Delete" /> - <span>'. $files[$i] .'</span></form>';
}
echo $reout;
- In "delfile.php" file:
Code: Select all
<?php
$re ='No $_POST data';
//if form data with 'delf' name
if(isset($_POST['delf'])){
$_POST['delf'] = urldecode($_POST['delf']);
//if file from 'delf' exists, delete it; else output message
if(file_exists($_POST['delf'])){
if(unlink($_POST['delf'])) $re ='File deleted: '. $_POST['delf'];
else $re ='Unable to delete: '. $_POST['delf'];
}
else $re ='The file not exists: '. $_POST['delf'];
}
echo $re;
JanMolendijk
thanks for the support it is working
Similar Topics
-
Delete Data without Refreshing Page
JavaScript - jQuery - Ajax
First post
Happy New Year Chief.... My first two weeks I spended on bed due to illness
I wanna use a script but it does not delete the item from my sql...
Last post
O God that I did not see this `stupido me`....
Thank you very much for all the support `its working now`
-
php mail two forms one button
PHP - MySQL
First post
Hello I found a mail script with add file`s function
only I would like to build a seccond mail-function
in it so the sender gets a copy from his...
Last post
Still mutch thanks for your support like allway`s
-
Stop button in Speech in Php
PHP - MySQL
First post
How are all things going CoursesWeb now with Covid-19.
It is shamble for all lovely lady`s who have the name.
I hope all Governements gonna make-up...
Last post
I could kiss you for this support all things working & I even have it now in Dutch
Thanks Coursesweb
-
Button to increment or decrement at random
JavaScript - jQuery - Ajax
First post
Quick question:
How can I set a button that can increment and/or decrement at random a number as it is clicked?
This is the code i have....
Last post
You can use Math.random() to decide whether you are going to increment or not:
<button id='tst_btn'>Change counter</button>
<h3...
-
Access an XML file from different domain in JS
JavaScript - jQuery - Ajax
First post
I am creating a website with HTML and JavaScript that relies on the data of an XML file hosted on a separate domain.
I can achieve this with...
Last post
Try using the the fetch api.
fetch('//example.com/file_address')
.then( response => response.text() )
.then( response => {
//response is...