Listing Directories in PHP - php

I have an < iframe > and when I "click" to one of the files .html that I show with this list it was appearing in this < iframe >. How can I do that?
I need to change the src that has the < iframe >. Now the only thing that it does is to open to a new page. Thank you.
<iframe id="probando" src="<?php echo $url; ?>" scrolling="auto" height="700" width="800" marginheight="0" marginwidth="0" name="probando"></iframe>
Since I can do that it changes the src that has the giving click. the only thing that it does is to open to a new . Thank you.
This is my code.
$directorioInicial = "./";
$rep = opendir($directorioInicial);
while ($arc = readdir($rep)) {
if ($arc != '..' && $arc != '.' && $arc != '') {
echo "<a href=" . $directorioInicial . "/" . $arc . " target='_blank'>" . $arc . "</a><br />";
}
}
closedir($rep);
clearstatcache();

If i understand you correctly, i think you need to change the target of the link to "_self" instead of _blank.
See this page for more info

Related

How to make a PHP echo into a link

I'm trying to get this so when I click the image, the image then shows in a new tab so it's able to be saved
I've tried adding the a href tags inside and around.
Code:
echo "<img src=" . random_image('css/avatars') . " />";
This is what you want:
echo '<img src="' . random_image('css/avatars') . '" />';
You should try
echo "<a target='_blank' href='".random_image('css/avatars')."'>"."<img src=" . random_image('css/avatars') . " /></a>";
I think this can help you
The problem is that you are not properly concatenating your string with what you get from random_image function.
You can try following code, here I am assuming that your random_image function returns complete path to your image
function random_image($path)
{
// returning dummmy image
return "https://images.unsplash.com/photo-1535498730771-e735b998cd64?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=623ed05afcc5a3fa1e444ffca95854dc&w=1000&q=80";
}
echo "<a href='".random_image('css/avatars')."' target='_blank'> <img src='".random_image('css/avatars')."' /></a>";

How to display images in navigable modal?

Need help!
I am creating an online portal for which I am displaying images as categories using PHP in grid format. I am displaying images from a folder.
What I am trying to do is create modal for images so that when I click on a particular image, the image Modal opens and displays that particular image in large size with navigation buttons so that I can navigate forward and backward to another image.
Here's what I have till now to just display images using php:
<?php
$cols = 4;
$colCtr = 0;
if($colCtr %$cols == 0)
echo "<tr><td colspan='2'></td></tr><tr>";
$folder = "./upload";
$results = scandir('./upload/');
foreach ($results as $result) {
if ($result === '.' or $result === '..') continue;
if (is_file($folder . '/' . $result)) {
echo '<td>
<a href="'.$folder . '/' . $result.'" target="_blank""/><img src="'.$folder . '/' . $result.'" target="_blank" alt="..." style="margin-left:50px;margin-bottom:27px;width:289px;height:190px;border: 2px solid black;" class="w3-hover-opacity hover-shadow cursor">
</td></tr>';
}
}
$colCtr++;
echo "\r\n";
?>
Thanks for your help!
You can use a lightbox javascript plugin to do that. Like: http://dimsemenov.com/plugins/magnific-popup/
Try this js plugin. It is easy to use is simple. http://sachinchoolur.github.io/lightGallery/

Ajax results to load into a iframe

I have a Ajax post that returns the path to a PDF file i can not seem to get it to open the pdf in an Iframe of on the parent page.
Parent Page:
<div id = "mainpage" ></div>
<iframe class ="box2" id="myFrame2" width="600px" height="700px" scrolling="yes" align="right">
</iframe>
</div>
<script>
function onAjaxComplete(msg)
{
$("#mainpage").html(msg);
// alert(msg);
}
when I click on the ajax request it returns the correct value and the function will display the results in the div but I can not get it to open the pdf file in the iframe.
This is the PHP script for the call from Ajax:
<?php
$sitej = $_POST['site'];
$filenamej = $_POST['filename'];
$pagej = $_POST['page'];
$path = "scann/" . $sitej . "/" . $filenamej;
//var_dump($_POST);
$load = "$path/#page=$pagej ";
//$open = '<a href="' . $path . '/#page=' . $pagej . '">';
//$load = '<a target="myFrame2" href="'. $open . '">';
echo $load;
?>
Any suggestions? Thank you in advance!
Change your jQuery to add the msg to the iframe src attribute:
function onAjaxComplete(msg){
$("#myFrame2").attr('src', msg); //No reason to select the div if you want to change the iframe src
// alert(msg);
}
This will return the iframe with the src from the php file.

How correctly refresh included PHP file?

I'm just a persistent beginner and I've met another obstacle in my way, so I hope that you'll help me one more time... :) I've got that HTML:
<div class='hold'><?php include 'image.php'; ?></div>
<div class='refresh'>Get new image</div>
And that PHP code:
<?php
$dir = 'images/';
$img = array();
if(is_dir($dir)) {
if($od = opendir($dir)) {
while(($file = readdir($od)) !== false) {
if(strtolower(strstr($file, '.'))==='.jpg') {
array_push($img, $file);
}
}
closedir($od);
}
}
$id = uniqid();
$smth = array_rand($img, 1);
echo '<img src=' . $dir.$img[$smth] . '?' . $id . ' width="200px" height="50px" />';
echo '<input type="hidden" value=' . $id . ' />';
?>
So now when I'm looking at my page I see in the <div class='hold'></div> my img from the folder images, and it's allright. BUT when I click on the <div class='refresh'></div> I obviously want to get another img from my folder, but I dunno how to accomplish that trick correctly.
I know that first answer will be USE AJAX, and I know that I can do something like
function loadGraphic() {
$('.hold').load('image.php');
};
loadGraphic();
and then $('.refresh').click(loadGraphic); but when I'm trying to do that in response from server I get TWO THINGS: image.php and, of course, something like car.jpg?573c4e010c7f6... But I very-very wanna get just ONE looking like
car.jpg?573c4e010c7f6
or
image.php?573c4e010c7f6 - I don't care...
So... I hope you've got my concept... maybe I'm asking for miracle - I dunno! Any, absolutely any help will be appreciated :)
Try it the following way:
JS function:
function loadGraphic() {
$.get("image.php", function(data) {
$(".hold").html(data);
});
};
Html:
<div class='refresh' onclick='loadGraphic()'>Get new image</div>

php rename swap file names doesnt reload image

i am working on a website that has a set of images and 1st image is like an avatar.. when i want to change the avatar (1st picture) what i do is i swap the 1st image name with the new image that i want to use as avatar.
I do this on an ajax function so i dont need to refresh the page after i do that.
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $pic_name, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $temp_name);
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $avafile, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $pic_name);
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $temp_name, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $avafile);
My problem is after i do that, i delete the images from the div and i add them again in the new order, but i think the browser saves the images somewhere and dont reload them and they appear in same order. Only after i refresh the page, they appear in the right order.
Is there like a solution to make the browser upload the images again ?
Thank you in advance, Daniel!
EDIT: This is the ajax function:
function avaPic(offer_id, pic_name, onFinish) {
var request;
if(window.XMLHttpRequest)
request = new XMLHttpRequest();
else
request = new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
onFinish();
}
}
request.open("GET", "php/script.php?action=avaPic&offer_id=" + offer_id + "&pic_name=" + pic_name, true);
request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
request.send();
}
and this is the php:
if($action == "avaPic") {
$offer_id = $_GET["offer_id"];
$pic_name = $_GET["pic_name"];
$filearray = getDirectoryList("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/");
$avafile = $filearray[0];
$temp_name = "temp.jpg";
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $pic_name, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $temp_name);
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $avafile, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $pic_name);
rename("C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $temp_name, "C:/wamp/www/invest/Coded/oferte/" . $offer_id . "/" . $avafile);
}
on the onFinish function, i refresh the div wih the images in hope they reorder again in the new order, but they appear same as they were before, untill i refresh the page
I found it, how to force the browser reload the images.
<div>
<img src="img1.jpg" />
<img src="img2.jpg" />
<img src="img3.jpg" />
</div>
instead this, i have to generate a html code with a time parameter in order to make browser reload the images. like this <img src='"img1.jpg?" + d.getTime()' />
Check will this solved your issue,
If you have your HTML like this,
<div>
<img src="abc.jpg" />
<img src="abc.jpg" />
<img src="abc.jpg" />
</div>
Just run this jquery after your ajax call
$('div img').attr("src",$('img').attr("src")+"?+"Math.random())

Categories