Posting file to PHP $_FILES from localStorage - javascript

It's surprisingly hard to find a definitive answer to this, I'm 95% sure what I'm trying to achieve is impossible, but here goes:
Front:
I have a multipart/form-data upload form. A user selects a file, but has to be logged in before he can post the form. The user can log in via Twitter. If he does so after selecting a file, due to the redirect to/from Twitter, the file input will be empty.
Back:
I have a PHP script using the $_FILES array to move the uploaded file to its final destination. (A solution to my problem would be to save the file to a temporary folder before redirecting to Twitter, but I currently can't set that up).
Problem:
I can store the selected file in localStorage using the FileSystem API (at least in modern browsers). But I obviously can't put that back in the input element. Now I'm at a loss: is there any way to get that file from my localStorage into the PHP $_FILES array?

Login to Twitter via ajax. This way you will stay on your current page and the file input will stay filled.

Related

Editing local file after hitting button

I'm trying to make a comment section for a locally hosted site, basically I am trying to make it so when you hit the submit button, it checks for a existing file, if it exists, then it will edit it, and put the comment into it, if it doesn't exist, then it'll create the file, and save the data, I'm trying to save it as JSON if possible, any ideas?
The only things I can find are to let the visitor save to the computer, which isn't what I'm trying to do, I want the site to only be able to access it. And I'm trying to not set up a server if possible.
You will definitely need some kind of backend server to do that since JavaScript runs on the client side. I can only recommend taking a look at a NodeJS http server that changes the files according to GET or POST requests or using said GET and POST requests in combination with a server-side PHP script.

How do I handle local file uploads in electron?

I'm having a hard time figuring out how to approach file uploads in atom electron. I would post code but I don't even know where to begin with this one.
In a standard web app I would post from the client to the server, either via a standard postback or using an ajax request. I have some pretty cool solutions for that. But in the case of electron, I'm not sure where or how to "post" the file back. I guess I just want to access the contents of my <input type='file' /> from node.js. How do I do this?
I could post to the browser process, but I don't know what the "address" would be. Or do I need to create a separate "page" in my app just to accept form posts? My background in web-dev is probably blinding me to some obvious answer, can someone help?
EDIT
Just to add a little more context, I have a .csv file which I'd like to allow the user to upload. I will then process this using node-csv and insert each returned row into the app's nedb datastore.
If you're going to process the file on the user's machine then there is no need to upload the file anywhere, it's already exactly where you need it. All you need to do is popup a dialog to allow the user to browse their file system and select the file they want your app to process. You can create a button and call dialog.showOpenDialog when the user presses it, that will get you a filename and you can then use Node's fs.readFile to read it from disk, then you can go ahead and process the contents in whichever way you want.

HTML/Javascript save string to server

I'm trying to create a button in my website that counts the clicks and saves them to a text file on the server. I managed to make everything else work like it should except sending the data to server.
I tried using PHP but that requires page refreshing and I don't want that.
Basically I need some help on how to overwrite a server text file with a variable (without having to refresh the page)
Is it even possible to do this without using PHP? (Page refresh everytime data is saved)
Thanks in advance.

How to store a Web page in localStorage to view at any time

I have a online web application form which I have to open every time and have to fill data and Submit.. So, I have got an idea of making a Google Chrome extension, that will make that page stored inside localStorage So that I can access it like a desktop page.. Is this possible.. I do not have any permissions to change the web site at server side.. I am just a client side programmer.. Is it possible? if yes please let me know how can I achieve this..
in theorie, yes, you could. Practically, it won't work out like you want. The reason are the external resources the website is going to be needing.
Storing just the html (document.body.innerHTML) would be possible. BUt if you want the formatting/layout to be happening, you'd need to save the computedStyles for each element as well. And if an image, you'd need to Base64 encode the image and save it.
Even if you'd succeed in saving the page, you'd need to know when to expire your localStorage cache and refetch the resources to stay compliant to the server side parsing of the form data (if they'd change something).
if its just about submitting a form, you also could just trigger the forms post-action-url directly by writing a script that resends the data you want sent.

Fill in a text field with a file system path

I have an HTML form and one the pieces of data we are collecting is a folder location. Right now the users have to manually input the path. I've been asked to make this easier. My thought was to provide a file input field, and have the user select a file in the needed folder, and then use javascript to parse the full file system path, and populate the other field. The product owners seemed to like that idea.
Since I have been trying to come up with some javascript to do this, and haven't been very successful. Any recommendations?
This information is deliberately inaccessible for security reasons.

Categories

Resources