How to write download to user's machine from website - javascript

I want a user to be able to download a file after entering their credentials on the webpage.
Currently I'm able to allow them download the file only if their browser has access to the hosting servers file systems. I saw this How to trigger a file download when clicking an HTML button or JavaScript.
This is what I'm doing currently:
Download
Excuse my naivety. My question is this: how do I change the path to file in:
Download
such that the user can directly download to their local machine when they don't have access to the hosting servers.

Related

Creating a directory picker to download a file to clients computer using js

I have written an application where on button click a .docx file is generated on the server and returned to client as base64 string. What I want to do now, is to let the user download the file in a directory of their choice.
To demonstrate what I mean, if I instead want to upload a file having a <input type='file'/> opens a dialog such like this
Where I can select the file. Is there any way to open this kind of dialog for a download button? I understand that the web-page doesn't receive the actual path on a clients pc for security reasons, but if you can chose an upload file, there is no reason to not chose a download path right?
No, for security reasons this is not possible.
See:
https://github.com/eligrey/FileSaver.js/issues/42

Is it possible to get access permission for a folder in local file system from browser

I want to make a local file editor. To open some files edit them and save them back. It's ok if it only works in Chrome. Using
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
I can read all the files and draw the file tree but I want to also be able to edit and save to these files. Even create new files and folders.
Is there any way to do it. I'm also ok with hacks that use Java or Flash or simply any other hack if HTML5 does not offer any solution.
Thanks
I do not believe what you are suggesting is possible; however, there is a different approach that should solve your problem.
If you take Microsoft's Online Word for example... They have it setup so you save document to the cloud and then can edit them with an online copy of Microsoft Word.
In otherwords, the user would upload a file. Your server would then take the file, display it and allow the user to edit the file. The user would then save the changes to the file. You can then provide an option to re-download the file.
To more closely emulate editing a file on the local file system, you can also setup a "temporarily" save on the server.
Essentially, the user uploads a file. The server would allow the user to view and edit the file. When the user wishes to save it, instead of saving the file on the server, give it back as a download to the user.
After the user leaves your site you can delete the copy of the file that is saved on your server.

Sending a created website to somebody

I am just a beginner in HTML (and soon JS), and I was wondering, once my website is complete (an html file made in either Sublime or Notepad), how do I get that website to other people? If I wanted to make a website eventually with my online portfolio of videos and images, how would I get it out to people?
Uploading website files are one of the very first steps users have to take in order to publish their creation on the Internet. This tutorial will provide a generalized example on how to upload a website using one of three basic tools:
What you’ll need?
Before you begin this guide you’ll need the following:
Access to the control panel of your hosting account
Your website’s files (preferably compressed in a .zip or .tar.gz
format archive)
(Optional) An FTP client and FTP login details of your hosting
account
Option 1 – Upload Your Website via Hosting's File Manager
Navigate to your control panel’s Files category and open File
Manager
After that, go to the public_html directory, which is the root
directory of your domain (for example http://www.domainname.com/).
Your files should be uploaded there. The directory may also be changed depending on what URL you want it to be accessed from. In case
you want the content to show up on
http://www.domainname.com/something/ your content would need to be
located in public_html/something directory.
To start uploading, right-click with your mouse and select Upload
Files option.
To unzip your archive, right-click it and press Extract.
Once the content is located in your desired location, you will be able to access it using any browser.
Option 2 – Uploading Your Website via FTP
Some users prefer using an FTP client, such as FileZilla, SmartFTP, CoreFTP, or any other in order to upload their website. In this example, we will use Filezilla.
Firstly, you will need to get your FTP details.they
are located in your control panel’s FTP Access section. If you are not sure what your FTP password is, you can easily reset it by pressing Change account password section.
Open FileZilla and input your FTP connection details into the fields
at the top of the program, then click Quickconnect.
Once you are connected to the FTP server, use the file browser on
the LEFT side of the program to find your website’s files on your computer. After you have found your website’s files, use the file the browser on the RIGHT side to open your public_html directory on the hosting server. Once you have done this, you can simply drag-and-drop files from left to right and they will be uploaded to the server.(OPTIONAL) Similarly, you can upload a compressed archive via FTP by dragging-and-dropping from left to right. You will also need to extract it via File Manager. Refer to the “Option 1 — Uploading your website via File Manager” part of the tutorial above for instructions on how to extract archives via File Manager.
Option 3 – Uploading Your Website via cPanel’s File Manager
Click on the File Manager icon, located under the Files category.
Once inside the File Manager, open the public_html directory.
Click Upload after entering the public_html directory.
You can click “Select File” to select a singular file, or simply
drag-and-drop your file to the outlined area.
Once the upload is complete, return to the File Manager and you will
see the uploaded archive in your public_html directory. Right, click
the archive and select Extract to extract the archive.
If you receive a prompt asking to specify the location the archive
should be extracted to, make sure to specify /public_html.
The archive is now extracted, all files should now be located inside
public_html. Navigate back to public_html and see if the files were moved successfully.
Your website should now be fully uploaded and accessible via your
website’s URL. All that remains is to access your website and check if everything works correctly. Simply type in your domain name in
your browser, such as http://www.domainname.com/, and check if your
website works to your satisfaction
you have just learned how to upload a website. As you may see, you can upload a lot of files at once via an FTP program more easily, however, each file will be uploaded one-by-one. As a result, it may take a long time for each file to be uploaded separately, so it is still strongly advised to create a compressed archive of your files before uploading them.
On the other hand, the File manager is useful for uploading one or two files quickly, since you do not need a separate program for the File manager to work and can update your website on-the-fly, while working on other tasks inside your hosting control panel.

Html get user local directory path

On my web app i have a textbox where client have to enter a path eg. C:\test and in that folder a file will be generated. The question is instead of manualy writing C:\test is there a way he can get this directory path with window that explores his system - like when uploading file.
The common use case is, the user clicks on a link and a file will be downloaded into his machine. This is usually done with anchor tag and the HTML5 download attribute. Here is an example:
<a href="~/images/abc.jpg" download>Click here to download </a>
The download action will be depended on the user's browser settings. In google chrome there is an option
"Ask where to save each file before downloading"
if it is checked, user will get a file explorer pop-up to select the download location.

file upload from local machine on local machine

Is it possible to upload a file from a local machine to the same local machine using JavaScript and/or server technology? The scenario was I had to get a image file from local , do manipulations/ cropping and then save it on that local machine. my website is hosted in another country.
You would need to upload the file to your server, using a normal file upload. After you have performed the manipulations you would provide a link for the user to download the file.
You cannot force the download back to local storage, the user has to accept the download.
Just use ImageMagick on the file itself, most hosting servers support it.
Maybe this helps:
http://mondaybynoon.com/2007/01/22/crop-resize-with-javascript-php-and-imagemagick/

Categories