I need to fetch complete the path from file select element of HTML using JavaScript. I have returned a JavaScript function, but it fetches only file name not the complete path.
How can I get the complete file path?
You can't. It's due to security. The browser only provides the content and the filename.
Providing the path could allow an attacker to learn things about the files on your hard drive that they want kept private. Do you really want to let the web server know that the kitty.png you are uploading for your avatar was actually in c:/pr0n/?
No, I didn't think so.
Related
I want to make a code using only JavaScript or/and jQuery to access a static directory and retrieve the names of some icons i saved there (SVG icons) and display the names to the user. i couldn't do that with the file api and i have no idea where to start.
I'm going to assume from your mention of jQuery and the File API that you're trying to do this within a browser.
You can't. It just isn't allowed, there is no mechanism to provide it.
If you're in control of the machine where you want this information to be accessed, you can run a server process on it that can do that; code in the browser can then make a request to the server code to request the information. But there's no browser-only way to do it.
I'm trying to update some text on a html page via jQuery ajax presently. This page's script calls an ajax request to a file in subfolder via jquery and displays that text.
I need to be able to update this file with text from a different html page.
I tried php, and found I didn't have file permissions to probably the ftp account or the webserver settings. Since php is the most popular method for file writing on a webserver, I haven't tried any other method.
I could try MYSQL + PHP for this, although I don't intend to put the root password in a text/php file.
I tried using Google Apps Spreadsheet with JSON output, and later found that JSON output was deactivated by Google (I guess).
Therefore, I was hoping to find a convenient way to get textual data from some source, and be able to update the textual data without any restrictions.
On most webservers, you will find at least one directory which is writable for PHP scripts. Else, you can place a file anywhere on the server and change the owner and write permissions, so that your PHP scripts will be able to write into that file. Please contact your webserver admin for details.
MySQL passwords in PHP files are no issue, as long as you put your PHP file outside of the directory that servers as root directory for your website. E.g. if your root is set to /var/www/user1/website1/, you can put a script inside /var/www/user1/, the PHP script shall be allowed to read that. This is the usual approach.
Environment:
html5
JavaScript
Angularjs
node.js
express.js
Couchbase
Question:
I understand the concerns and security measures implemented within the web environment to prevent the display of directory paths to the world. However, I have an issue that requires knowing the full directory path to a selected file.
I am building a web page for an internal website. The web page needs to allow the user to select a tab delimited file. This tab delimited file will exist on a network server, which is a policy instituted by the company and mandated by external auditors. This file may exist for various clients, with data specific to the client. With that said, the files will reside within different folder structures on the server(s). The user wants to pick the appropriate file and have the data uploaded to the database. Based on the size of the file (up to 10’s of millions of rows), the user does not want to wait for the web page to process immediately. Therefore, the solution is to create a task. The task will contain all the parameters necessary to manipulate the data prior to uploading the data to the database. I understand the simple solution is to upload the file to a common directory but that is not practical. As the user could set up several tasks that will upload the same tab delimited file to the database using different parameters.
I would like to have my task creation process contain the file name with the directory structure. When the background process executes the task, it can extract the data from the original location. Additionally, if I have multiple tasks extracting the same data, I not concerned I may have multiple copies of the data present.
I will appreciate any help with code snippets, website, etc. that may suggest methods to resolving this issue. Please not, that at the current moment, PHP is not an option. A management decision prevents the use of PHP.
TIA
Anthony
It is not exactly possible, so I see two solutions. One is to try and get the path to the temporary location of the file, rather than the actual permanent location.
Suppose your has an id of fileInput and you're using jQuery:
$('#fileInput').change( function(event) {
var tmppath = URL.createObjectURL(event.target.files[0]);
console.log("Temporary Path(Copy it and try pasting it in browser address bar):"
console.log(tmppath);
});
Otherwise I would just make a separate input for path, and show a brief instruction to users on how to copy-paste the URL from their Windows Explorer window.
I have a website that allows users to select a date range from a data set. At least, that's the goal.
What I would like to have happen: the user selects a date range, presses the submit button, and a script generates a JSON file which MATLAB reads to generate the graphs.
Any thoughts on resources to help accomplish this?
You'll need the script that fires off to be server side. JavaScript is client side and can not, in any way, access, modify, or otherwise create files on the client. You'll have to use a language like PHP to create the file.
Example using PHP:
Once the file is created, force a request on the client side to fire asking for the file. Set the PHP header to Content-Disposition: attachment; filename="< Place file name here>".
This will prompt the browser to launch a download prompt allowing the user to download the file.
Hope this helps.
You can use Downloadify, a small Flash component with a Javascript interface that allows you to create files on the client that a user can download. That's what I used in a similar situation.
You could also try and use Data URI but they are a quite limited and browser specific so some issues may arise.
These may be alternative solutions to the previous answer that suggested using server side code to generate the file.
Hypothesis: I have thousands of images into different folders in an amazon S3 bucket. I'd like to make them accessibile to unlogged users as slideshow, but I don't want to deal with db and server poor performance (in case of too many users at the same time) , so I'd like to use only javascript.
The problem is that I should however deliver to the client the file list, since I can't use XMLHttpRequest to fetch and parse the xml file that Amazon provides when you try to browse a bucket because (I expect) the browsing page should be located on my webserver.
I think I should write some server-side code to create,after every upload/modification, an updated filelist to share with users, but I'm not sure it's a good idea.
Can anybody suggest me the best way to proceed?
Happy New Year!
Possible answer, tell me what do you think about:
Amazon provides ListBucket operation http://docs.amazonwebservices.com/AmazonS3/latest/API/SOAPListBucket.html
I can choose how many results to get at once using max-keys and marker (for pagination) parameters (example: http://download.terracotta.org/?max-keys=5).
I will obtain a xml file (as smallas I want) that I can parse locally with js in a "list.html" file, for example.
I could then include this list.html file (that should print just the definition of an array of images) in a iframe included in my slideshow.html file on my webserver.
Too dirty?
The Amazon S3 JavaScript API has a method, bucket.list() that will list the contents of a bucket.