a bit of a weird one, but I have figured out how to use glob to display a list of images, and now I want to add a button under each image that would let you delete each image individually, I think I just need to use unlink, but whenever I try it just seems to delete every file on the server!:')
Here is the code I have so far:
<?php
// This sets the variable $filelist, and get it to search the specificied levels of wildcards for jpg, png, JPG, and PNG using glob:
$filelist = glob('{*.jpg,*/*.jpg,*/*/*.jpg,*/*/*/*.jpg,*/*/*/*/*.jpg,*/*/*/*/*/*.jpg,*.png,*/*.png,*/*/*.png,*/*/*/*.png,*/*/*/*/*.png,*/*/*/*/*/*.png,*.JPG,*/*.JPG,*/*/*.JPG,*/*/*/*.JPG,*/*/*/*/*.JPG,*/*/*/*/*/*.jpg,*.PNG,*/*.PNG,*/*/*.PNG,*/*/*/*.PNG,*/*/*/*/*.PNG,*/*/*/*/*/*.PNG}', GLOB_BRACE);
// This filters the above into date order from newest to oldest:
usort($filelist, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
// This is how I now output the data, basically looks for each value of $filelist and sets it as $link, then outputs this and concatenates it with itself as a href and a background-image:
echo '<div class="thumbnail-grid">';
if($filelist){
foreach($filelist as $link){
echo '<div class="tile-container">';
echo '<a style="background-image: url('.$link.');" class="photo-link" href="'.$link.'"><i class="fas fa-link"></i></a>';
// This adds in a delete button:
echo '<form method="post"><input style="cursor: pointer;" name="delete" type="submit" value="DELETE"></form> ';
echo '</div>';
// This is the script that should be doing the unlinking:
if(isset($_POST['delete']))
{
unlink($link);
}
}
}else{
echo ' No images found.';
}
echo '</div>';
Hope this all makes sense/isn't asking too much!
Many thanks, Jack.
This isn't very secure as anyone can send a POST variable with a filename and delete it.
But as an example, you can loop through the files and give the delete button a value of the filename and then when you check for the posted delete button delete the file.
// This is the script that should be doing the unlinking:
if(isset($_POST['delete'])){
unlink($_POST['delete']);
}
if($filelist){
foreach($filelist as $link){
echo '<div class="tile-container">';
echo '<a style="background-image: url('.$link.');" class="photo-link" href="'.$link.'"><i class="fas fa-link"></i></a>';
echo '<form method="post">
<input style="cursor: pointer;" name="delete" type="submit" value="'.$link.'">
</form> ';
echo '</div>';
}
}else{
echo ' No images found.';
}
Related
I created a database with a table that contain information about thousands of tracks.
One of these informations is the directory of the track to play when i click "Play".
while($row = mysqli_fetch_array($sqldata ))
{
echo "<tbody><tr><td>";
echo $row['position'];
$path = "audio/";
$track = $path . $row["path"] . ".mp3";
echo "</td><td>";
echo '<input type="image" src="images/play.png" width="20px" height="20px" onclick="play();">';
echo "<audio id='audio' src=$track></audio>";
echo '<input type="image" src="images/pause.png" width="20px" height="20px" onclick="pause()">';
echo '<audio id="audio" src=""></audio>';
echo "</td><td>";
etc..
The problem is that when I click "Play" in all of different tracks it play only the first track of "audio" folder.
What is the correct method to play different tracks depending on rows?
Thanks
SOLVED.
This is the solution:
Delete multiple audio tags and set only one audio tag out of table.
Send the path in the column as parameter to javascript play function and edit audio.src then audio.load and then audio.play.
echo '<input type="image" src="images/play.png" width="20px" height="20px" onclick="play(\''.$track.'\');">';
IMPORTANT: quotes and backslash are important to send a string.
Thank.
By compiling this, display three image get my database and show it, when i click each image popup window show last image of my database.I want to know how to display the particular image, when i click first image,then popup window show first image and description, as well as same way second and third image. check to array loop in this code...
enter code here
<?php
$sql=mysql_query("select * from product_reg")or die(mysql_error());
while($row=mysql_fetch_array($sql))
{
$productname=$row['productname'];
$productid=$row['productid'];
$description=$row['description'];
$image=$row['image'];
$firstN = array();
$i=0;
$firstN = '<img src="'.$row ['image'].'">';
echo ' <a href="#" class="big-link" data-reveal-id="myModal" name="image" style="float:left;margin:100px 0 100px 100px;"> ' ; echo $productname;echo $firstN[$i];
$r=$firstN[$i];
echo '</a>';
$i++;
}
?>
<div id="myModal" class="reveal-modal">
<form>
<table>
<tr><td><?php echo $r; ?></td>
<td><h1>Reveal Modal Goodness</h1>
<p>This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.</p></td>
<a class="close-reveal-modal">×</a>
</div>
</body>
</html>
I guess you have the images stored in the database like BLOB data. If so you need to create a handler to retrieve those images and render them as image/[mime]...
So in short.
In your code you need to create a new file iz get_image.php in it you need to make a request to the server and retrieve the image so you can send it to the client.
In your code you need to change the image path to the handler path with some query parameters.
$firstN = '<img src="get_image.php?imageid='.$row ['productid'].'">';
There are a lot information how to render the image to the client from the internet.
may be you have to declare your $firstN = array(); and then incrementor $i=0; out of while loop and put in array like this:
$firstN[$i] = '<img src="'.$row['image'].'">';
below is the full code:
<?php
$sql=mysql_query("select * from product_reg")or die(mysql_error());
$firstN = array();
$i=0;
while($row=mysql_fetch_array($sql))
{
$productname=$row['productname'];
$productid=$row['productid'];
$description=$row['description'];
$image=$row['image'];
$firstN[$i] = '<img src="'.$row['image'].'">';
echo '<a href="#" class="big-link" data-reveal-id="myModal" name="image" style="float:left;margin:100px 0 100px 100px;"> ';
echo $productname;
echo $firstN[$i];
$r=$firstN[$i];
echo '</a>';
$i++;
}
?>
Updates:
You have a space here:
$firstN[$i] = '<img src="'.$row['image'].'">';
//-----------------------------^----here at this code block;
To get the last image , you need to modify your query to have SORT BY productid DESC
To display the images
echo "<a href='xxx.php?imgid=$image'><img src='yourimagesfolderpath/$image.jpg'> </a>";
to navigate in the images , you have to use JQUERY
I don't know exactly where to start to display files from the file set in order to show a fancybox gallery on click. I would like to have the gallery open from a link. On click show the gallery, aka images that have the same rel but are set to display:none (easily controlled by my css). I can do it from selecting one image but am not sure how to pass the images from the file set into the view (I'm assuming I need to create some kind of function in my controller to get the fsID, just not sure how). I just need the first image to display on the page (thumbnail image), then click the link and it shows more full size images.
Basically, if you know Concrete5, I would like it to be like the image block, except that the administrator can choose a fileset instead of one image.
here is my view.php
$picture = $this->controller->getPicture();
if ($picture) {
$bigPicture = $image->getThumbnail($picture,600,600)->src;
$smallPicture = $image->getThumbnail($picture,200,200)->src;
echo "<img src=" . $smallPicture . " alt=" . $imageTitle . " title=" . $imageTitle . "/>";//thumbnail picture
echo "<div id=\"image-modal\">";
echo "{$linkText}";//open fancybox from link
echo "<div class=\"hiddenGallery\" style=\"display:none;\">";//hidden images
echo "<a href=\"images/pattern/t-103-n.jpg\" class=\"fancybox-thumb\" rel=" . $title . " title=" . $imageTitle . ">";
echo "<img src=\"images/pattern/t-103-n.jpg\" class=\"fancybox-thumb\" />";
echo "</a>";
echo "</div>";
echo "</div>";
}
my controller.php
function getPicture() {
if ($this->fIDpicture > 0) {
return File::getByID($this->fIDpicture);
}
return null;
}
my add.php
$al = Loader::helper('concrete/asset_library');
echo $al->image('ccm-b-image', 'fIDpicture', t('Choose File'),
$this->controller->getPicture());
echo '</div>';
Any and all help is much appreciated.
Well, two things :
You have to set the class="fancybox-thumb" AND the rel attribute to the <a> tag!!, not to the <img /> tag.
If you are planing to hide the rest of the elements of the gallery, don't set a display: none; css property to each of them, but rather wrap them in a hidden <div> container like :
<div style="display: none;">
<a class="fancybox-thumb" rel="gallery" href="images/02.jpg"></a>
<a class="fancybox-thumb" rel="gallery" href="images/03.jpg"></a>
<a class="fancybox-thumb" rel="gallery" href="images/04.jpg"></a>
... etc
</div>
I am using the rendered html, which is what it matters.
I have some code which handles the entire back-end (add/edit/controller) part of this equation:
https://github.com/jordanlev/c5_designer_gallery
Here's a tutorial that explains how to use it (with the example of the FlexSlider, but if you know how Fancybox works then it shouldn't be hard to understand what's going on):
http://c5blog.jordanlev.com/blog/2011/12/build-a-slideshow-block/
How can I delete all the listed files using PHP? As shown in the code, it displays all the files in the folder with a "Delete" button next to each one... but how can I use the unlink function to delete the particular file when its "Delete" button is clicked?
function Deletion()
{
$files1 = scandir('upload/');
$ignore = array( 'cgi-bin', '.', '..');
foreach ($files1 as $file1)
{
if(!in_array($file1, $ignore))
{
echo '<div>
<img src="upload/' . $file1 . '" height="50px" width="50px" />
<input type="button" value="Delete" name="del"/><br>
<a href="upload/'.$loca.'/'.$file1.'" target="_BLANK"
style=" font-size:12px; color:#333;"><p >'.$file1.'</p></a>
</div>';
}
}
}
You would need to perform an action on the server side when the button is clicked. Use AJAX to make a GET request to a page on your server with the filename as a parameter and then run unlink on the GET parameter. I generally suggest jQuery to beginners in AJAX.
JavaScript:
jQuery.post("delete.php", {file: "dont-want.php"})
PHP:
unlink($_POST["file"])
if(!isset($_POST['JoinFaction'])) {
echo '<form method="post" action="'.$page_name.'"><dl id="sample" class="dropdown" align="left">'
.'<dt><a href="#"><span>Recruiting Factions ['.$numrows.']</span>'
.'</a></dt><dd><ul>';
while($faction_re = mysql_fetch_array($sql)){
echo '<li><a href="#">'.$faction_re['f_name'].''
.'<span class="value">'.$faction_re['f_id'].'</span></a></li>';
}
echo '</ul></dd></dl></td>'
.'<td class="faction_bgcolour" align="center"><input type="image" '
.'name="JoinFaction" value="JoinFaction" width="54" height="45" '
.'src="images/global/game/faction/join_faction.png" /></td></form>';
//get output as a variable to use in later code
echo $selected_faction = '<span id="result"></span>';
} else { $selected_faction = '<span id="result"></span>';
echo '<div class="faction_text">Joined: '.$selected_faction.'.</div>';
}
when I:
echo $selected_faction;
in the if statement, it gets the right faction value (i'm using custom jquery drop down boxes by the way here).
The problem is that this id is not being passed to the else statement where i can update the database. I'm really not sure how I would pass the id on to the else statement.
echo $selected_faction is blank in the else clause
Any help would be greatly appreciated.
You're going to need to send the content of that div back to your server with AJAX.
You could start learning here: http://api.jquery.com/category/ajax/
I suppose a good starting point might be: http://api.jquery.com/jQuery.post/