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())
Related
I'm setting a variable based on an array. When I echo the variable it displays on the screen, however when I try to add it to a Header Location it doesn't show up in the URL of the next page - everything else does:
$myid = $selected_cat3[0]['id'];
Header("Location:/cat-dashboard/cat-results/?catID=" . $myid
. "&question1=" . $_GET['question1'] . "&question2=" . $_GET['question2']
. "&question3=" . $_GET['question3'] . "&question4=" . $_GET['question4']
. "&question5=" . $_GET['question5'] . "&question6=" . $_GET['question6']
. "&question7=" . $_GET['question7'] . "&question8=" . $_GET['question8']);
This is the generated url:
/cat-dashboard/cat-results/?catID=&question1=0&question2=3&question3=1&question4=1&question5=1&question6=2&question7=1&question8=3
Am I doing something wrong? It doesn't show even if I use: $myid = "1";
I am working on a form, and want to save a copy of every form submitted. The problem is the form's action is a counting file, that makes each file saved count up once. For example, the third form submitted is named "3.php", and the tenth form submitted is named "10.php". When I try to write the POST variable top the new file, it is gone. Anyway I could write their responses to a new document with my counting files code?
Form code on main file:
<form action="count.php" method="post">
<input type="text" name="formItem1">
<input type="text" name="formItem2" required>
<input type="text" name="formItem4" required>
<input type="text" name="formItem5" required>
<input type="text" name="formItem6" required>
<input type="submit" name="Click" value="Submit">
</form>
Count.php code:
<body>
<?php
define('countlog.txt', __DIR__ . "./");
if (file_exists('countlog.txt')) {
# If File exists - read its content
$start = (int) file_get_contents('countlog.txt');
} else {
# If No File Found - Create new File
$start = 1;
#file_put_contents('countlog.txt', "$start");
}
# When Form Submitted
if (isset($_POST) and isset($_POST['Click']) and $_POST['Click'] == "Submit") {
$file_name = "{$start}.php";
$template = file_get_contents('template.php');
#file_put_contents("./submissions/" . $file_name, "$template");
# Update Counter too
$start = $start + 1;
#file_put_contents('countlog.txt', "$start", 1);
echo "Generated Filename - $file_name";
}
?>
</body>
Template.php code:
echo "<h1>Answer1: " . $formItem1 . "</h1>";
echo "<h1>Answer2: " . $formItem2 . "</h1>";
echo "<h1>Answer3: " . $formItem3 . "</h1>";
echo "<h1>Answer4: " . $formItem4 . "</h1>";
echo "<h1>Answer5: " . $formItem5 . "</h1>";
echo "<h1>Answer: " . $formItem6 . "</h1>";
Use sessions. Create a session on each page with session_start(); Store the post value using the session global array. eg. $_SESSION['yourValue'] = POST['yourValue'];. Now on the rest of the pages you should be able to access the value. e.g
$yourValue = $_SESSION['yourValue'];
IF you use $template = file_get_contents('template.php'); it will make the content of template.php a string, and the variables will not be evaluated.
You could use eval() http://php.net/manual/en/function.eval.php to evaluate a string as PHP code. I would not recommend this method, but if you want to use it you will need to return, rather than echo the template otherwise the template will be echoed to the browser rather than the string you want to save to file.
template.php
return "<h1>Answer1: " . $formItem1 . "</h1>".
"<h1>Answer2: " . $formItem2 . "</h1>".
"<h1>Answer3: " . $formItem3 . "</h1>".
"<h1>Answer4: " . $formItem4 . "</h1>".
"<h1>Answer5: " . $formItem5 . "</h1>".
"<h1>Answer: " . $formItem6 . "</h1>";
count.php
$template = file_get_contents('template.php');
$template = eval($template);
It would be much easier/better to include the template, and the code will execute, thus populating the $template variable.
template.php
<?php
$template = "<h1>Answer1: " . $formItem1 . "</h1>".
"<h1>Answer2: " . $formItem2 . "</h1>".
"<h1>Answer3: " . $formItem3 . "</h1>".
"<h1>Answer4: " . $formItem4 . "</h1>".
"<h1>Answer5: " . $formItem5 . "</h1>".
"<h1>Answer: " . $formItem6 . "</h1>";
?>
count.php
include('template.php');
Both methods assume you have used extract($_POST); to import variables from an array into the current symbol table.
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
can anyone tell my why this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='../images/producten/monster_energy_green.png' alt='' /></a>";
does give a clickable image link, and this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt'productafbeelding' /></a>";
doesnt? (not clickable).
thanks in advance!!
php rookie..
In the first one you have a real scr it's directing to with a file extension. the second does not. If the second is supposed to be picking up a variable we would need more information
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt='productafbeelding' /></a>";
just add a "=" between alt and 'productafbeelding'
Try this one:
echo '<img src="' . $rij['afbeelding_klein'] . '" alt="productafbeelding" />';
This is a followup to the solution for this question.
I am using jQuery's load() function to pull a headline within a div tag from one page to another within my site. This works wonderfully.
The problem is, load() also pulls the div tag itself, which I do not want, as it then gets formatted via CSS like the source page.
Here is the PHP:
function get_team_articles($team_id, $feat=0) {
.
.
.
while ($row = mysql_fetch_assoc($r)) {
$page = explode('_', $row['page_id']);
(is_numeric($page[1]))
? $pre = 'wk_'
: $pre = '';
$arr[] = $page[0] . " | " . $pre . $page[1] . ": " . "
<a linked_div='news_header'
linked_path='../news/" . $page[0] . "/" . $pre . $page[1] . "/" . $page[1] . "_" . $page[2] . ".html'
href='index.php?view=news&yr=" . $page[0] . "&wk=" . $page[1] . "&pg=" . $page[2] . "'></a>";
}
$articles = implode('<br/>', $arr);
return $articles;
}
Notice the linked_div and linked_path attributes within the anchor tag, which are used in my jQuery:
function set_team_headlines(){
$('#section-articles > a').each(function() {
var a = $(this);
a.load(a.attr('linked_path') + ' #' + a.attr('linked_div'));
});
}
Obviously I cannot strip the HTML tags within the anchor tags in PHP, because the server doesn't have the text within the anchor tags upon loading; so I assume I need to strip the HTML in jQuery after the load() call...and that is what I cannot figure out how to do. :)
The result I want is:
My headline
The result I'm getting is:
<div id="news_header">My headline</div>
Hopefully this makes sense. I think I provided more detail than I needed to. Thanks!
Navigate down one more level in your .load selector
a.load(a.attr('linked_path') + ' #news_header');
If your news_header id isn't unique, it isn't valid to select by that id (ID's must be unique!)
To get around that issue, use this:
a.load(a.attr('linked_path') + ' #' + a.attr('linked_div') + ' div');
Edit:
.load actually includes the targeted element when appending html instead of appending the target element's children. I would move to using $.get().
$.get(a.attr('linked_path')).done(function(html) {
a.text($(html).filter("#news_header").text());
});