This question already has answers here:
Secure files for download
(2 answers)
Closed 8 years ago.
i was wondering, when someone is downloading a file, lets say a .zip file, is it possible to hide the url where the .zip is stored?
I use a link to the .zip file to download it like this:
<a class="BigButton"href="http://www.webprofis.nl/demo/vd/1/validation- contactform/validation-contactform.zip">DOWNLOAD contactform </a>
When mouseover the link, everybody can see where the file is stored...
You can do this only with javascript.
Here is a little example with jQuery:
Download link
<script>
$('a[data-link]').click(function(e) {
e.preventDefault();
window.open($(this).attr('data-link'));
});
</script>
If you make the href='#' then add an onclick event you could use javascript to redirect the user to the zip file. However, if something views the source of your page it'll still show it there.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am building a php web app in which I want to get all the files in a specific folder and display it to the user (each user has their own folder to store their records) I have managed to upload files using Dropzone.js and I can also display the files using Dropzone.js as well but I can't figure out how to let the client download them or open them. Is there any way to use dropzone.js to open the files when clicked if not to download them in the client computer? Or examples on what other libraries to use to display files and open if possible or download them (the files are images .pdf and word files)
Thanks
The are several ways you can do this, one simple way is to send back from the server the url of the image you just upload, and add a link to the image.
In the following example I am wrapping the image preview that dropzone creates with a <a> tag, that lets you download the image when you click the preview using jquery:
html:
<form action="upload.php" class="dropzone" id="my-dropzone"></form>
js:
Dropzone.options.myDropzone = {
init: function() {
this.on('success', function(file) {
var url = file.xhr.response;
$('.dz-preview.dz-success').last().wrap(function() {
var link = $('<a/>');
link.attr('href', $.trim(url));
link.attr('download', true);
return link;
});;
});
}
}
php:
if(move_uploaded_file($_FILES['file']['tmp_name'], 'uploadsFolder/' . $_FILES['file']['name'])) {
echo 'uploadsFolder/' . $_FILES['file']['name'];
}
This question already has answers here:
Events triggered by dynamically generated element are not captured by event handler
(5 answers)
Closed 8 years ago.
page-one.php contains such jquery
$.post("___for_ajax_process.php", data_to_send_ajax_post, function(data_edit_content) {
$('#show_result').html(data_edit_content);
});
in #show_result i see content from ___for_ajax_process.php
Rendered content contains many checkboxes and want to create check all. check all is named draft_check_all.
At first want to check what happens if I click the checkbox.
$("#draft_check_all").click(function(){
alert ( 'click test' );
});
And I do not see alert ( 'click test' ); No popup at all.
Then View source and I do not see source code for content rendered by ___for_ajax_process.php
As understand in such way can not apply jquery to content from ___for_ajax_process.php? What if place $("#draft_check_all").click(function(){ in ___for_ajax_process.php? Are there any solutions for such situation?
Solution
placed jquery in external php and all works!
A better solution would be event delegation.
$('#show_result').on('click', '#draft_check_all', function () {
...
});
This question already has answers here:
How do I redirect to another webpage?
(58 answers)
Closed 9 years ago.
Can I use a header location in jQuery for redirection or refresh?
Like in PHP:
header('location:www.google.co.in');
header("Refresh:1,url=home.php");
If not, what is the alternative way?
Headers are interpreted prior to the rendering of the document, and before jQuery is even loaded so these aren't an option. Instead, you can redirect the browser using document.location.
document.location.href = 'www.google.co.in';
For a jQuery approach you can use
$(location).attr('href', 'www.google.co.in');
however I would favor the plain javascript version.
You can use:
window.location.assign('www.google.co.in');
or
window.location.href = 'www.google.co.in';
or
window.location.replace('www.google.co.in');
The difference is that assign() will just cause a new document to load. While replace() will replace the current document and replace the current history with that URL making it so you can't go back to the previous document loaded.
Use
window.location.href="www.google.co.in";
for redirection.
and
window.location.reload(true);
to reload the page
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I run PHP code when a user clicks on a link?
I have an image .
<image name="" src="">
I have a php code that needs to be run only after the image has been clicked.
<?php
$var = somthing;
if(condition)
{
sql stmts;
}
?>
like that.
Both are in the same php page. PLease help me to sort out this problem.
Thanks..
You can send a request with javascript. With jQuery that would look like this:
$.get("yourfile.php?function=imageClick", function(data){});
In your php somewhere at the top add:
if($_GET['function'] == 'imageClick'){
// do your php stuff
}
You can't run PHP code on the client side.
You can do that through an AJAX call: http://www.w3schools.com/ajax/default.asp
This question already has answers here:
How can I convert language of a div?
(4 answers)
Closed 7 years ago.
"<div id="diva">this is div a</div>"
"<div id="divb"> this is div b</div>"
now how can I change the text of div dynamically by button click. here also mention that all text come from a database. when I click the button then it detects the div id and replace the text with desire text.
All code will be in PHP.
This will work once the page is being loaded:
document.getElementById('diva').innerHTML =
<?php echo functionThatReturnsSomeValue(); ?>;
Dynamically, you would need to do an AJAX call on the PHP file which outputs a value. You'd be better off if you used a JS framework such as jQuery, rather than implementing the AJAX call yourself.
PHP cannot modify the content of the page after it has been served to the browser. However this would be trivial with a JavaScript Library such as jQuery.