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'];
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a textarea in my html like this:
<textarea id="area1"></textarea>
When visitors copy/paste or type something in this area i want it to save to a txt file without the visitor having to click any button.
Looked all over the web but can't find any solution.
write JS function, that saves info in .txt file. Let's say, function name is saveToTxt(). Then trigger that function onChange:
<textarea id="area1" onChange="saveToTxt(this);"></textarea>
EDITED
Assume that, saveToTxt() is something like that:
<script>
function saveToTxt(fld) {
const textAreaValue = fld.value;
// then use textArea variable as container of textarea-content
// and then treat it as you want.
}
</script>
This example show how to save content automatically 2s after changing. It can prevent from doing save for every character typed.
var t;
function save() {
clearTimeout(t);
t = setTimeout(function() {
console.log('All changes saved'); // save here
}, 2000);
}
<textarea onchange="save();" onkeyup="save();"></textarea>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
how can I specifically convert this php below code to html? I want to do this as I want to be able to run this code on my website.
From reading other forum posts I understand about people saying them link the PHP file externally using something like this php. However, from my understanding my PHP code is slightly different in terms of the output and I'm just not sure.
Below is my php code I want to run externally on my site from the html file.
<?php
echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
print_r($browser);
?>
Can you use Ajax and show the result in HTML
<script>
$.ajax({
urL:"./tomy.php",
type:"POST",
data:{getuserAgent:1},
success:function(data){
$("#mydiv").html(data);
}
});
</script>
tomy.php
<?php
if(isset($_POST['getuserAgent']){
echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
print_r($browser);
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a table with add, edit, delete options. Now I want to hide divs with buttons for not logging users.
Or maybe I should make a deactivated buttons for not loggin users?
when user login then you have session like
$_SESSION['email']=$email;
then used this code
<?php
if(isset($_SESSION['email']))
{
echo "<div>any text</div>";
}
?>
do some effort to write the code
Depending on how your site works there are two possible solutions that I can think of.
USE PHP
If the user is logged in then use:
<?php
if ($logged_in) {
?>
<div>Your text here</div>
<?php
}
?>
NOTE: You do not need to use "echo" or "print" if you close and open your PHP tags between the "if" as shown below. This can make the HTML part of the much easier to read and write.
USE JAVASCRIPT
If the page does not reload when the user logs in then you will need to use Javascript to hide and show the DIV using something like:
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
First of all, I'm a beginner in PHP. I'm trying to design a simple application to practice handling form elements. Basically, I upload an image, push submit, and then the image gets displayed in the web browser. The form works perfectly, but I'm having trouble displaying the image once I store it into a variable.
Does anybody know how to do this?
<html>
<head>
<title>HI</title>
</head>
<body>
<form action = "blah.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "dope">
<input type = "submit" value = "Upload Images" name = "submit">
</form>
</body>
</html>
The PHP file is:
<?php
$image = $_FILES;
imagejpeg($image);
?>
You can simply get the mime type from the upload and read it back to the browser:
header('Content-Type: ' . $_FILES['dope']['type']);
readfile($_FILES['dope']['tmp_name']);
This will send a header with the correct mime type so the browser knows how to handle it, if it's an image it'll be handled inline, if it's an application the browser will download it. readfile reads a file and sends it to directly to the buffer.
Be aware that if you want to store the file for future reads you will want to move it and store the location in a database or similar using move_uploaded_file, e.g.
move_uploaded_file($_FILES['dope']['tmp_name'], $destination);
Then you can serve the file over and over providing $destination contains the file path:
header('Content-Type: ' . mime_content_type($destination));
readfile($destination);
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.