I need to create a CSV File editor. The user should be able to upload a CSV file, and the data should automatically be loaded into a text area. I have seen many examples of CSV data being transferred from a text area to, for example, a table, but I can't find something that will help me with actually uploading a file, reading the data from it in to a 2D array, and then placing it in a text area.
I can transfer the data into an editable table from the text area without problem.
So the question is: How can I upload a file, read the data from it (and keep the format of the CSV) and display the correct format in a text area element?
I am not currently concerned about checking to see if the CSV is correct etc etc. I just need to know how to handle the data. Sorry, but my Ajax knowledge is very limited. Any help or guidance would be appreciated.
Uploading it is no different than how any other form works in HTML.
You can use a file input to select a file, then upload it as part of the form data (it's automatic) or supply the user with a textarea to paste into. Submitting the form will "upload" the data to the server. You don't need AJAX to do any of this, but it is an option.
What you do with the data on the server is up to you.
Related
How to upload , display and save image in a database. jQuery JavaScript using API calls .
I have four fields in db
File I'd
Filename
Filesize
Filepath
I don't see any mention of server side languages such as PHP listed here, but you need some sort of server side implementation to upload an image and deal with the database.
Ill help you go in the right direction so you know what to look up and look for.
Uploading an image
To upload an image you would conventionally use a form element with an input of type file. The form action would be your php upload script. The upload script can be complex, but they tend to be the same once you get the hang of it. Take a look at this page: https://www.w3schools.com/php/php_file_upload.asp. It has a full php upload script.
Store in database
To 'store' the image in the database you just need to save the path to the image. This means you will need to setup your SQL database, and a table. Then use PHP's SQL database functions to INSERT the link into the table, along with your other data.
Display the image
To display the image you will need to use a php script to gain access to the database, and then use a specific ID to get the image path out of the table and output it to the page.
Conclusion
Uploading files is an age old problem, and is tough until you've done it a few times. In the comments i saw mention of dropzone.js, which is really great for handling the uploading of multiple images but it does not actually do the uploading, you still need to write some php. Dropzone is purely a front end tool.
Hope that helps you move in the right direction!
I was looking around trying to find a solution but was unable one. What I want is the take whatever the user enters into text fields and save those into an xml file. Then I want to prompt the user to save that file.
What I mean is to get the info from many different input fields through document.getElementById('id').value and put that into the file.
For example:<lessonname>document.getElementById('lessonname').value</lessonname>\n
I have a requirement where i need to store the data selected by user into the txt file. How can i do that? My form is in html and javascript.
The only way I know how is with php. Any other server side language would work.
The following tutorial has everything you need to know about working with files using php.
http://www.tizag.com/phpT/files.php
create file: http://www.tizag.com/phpT/filecreate.php
write to file: http://www.tizag.com/phpT/filewrite.php
be careful here. You need to choose the correct method of writing to the file depending on weather you want to add to what is already in the file or override it. To append see this: http://www.tizag.com/phpT/fileappend.php
At a form, I have a file input field (for image) and I want to add an optional way to fill this field by fetching data via ajax API and this returns me the URL of an image.
How can I set the content of the field input as the URL image, especially is it possible without passing a hidden a hidden text field to pass this image URL to the server?
File inputs are for uploading the content of files from the client to the server. Since browsers won't let you (as a page author) download a file on behalf of the client, this isn't possible.
If what you were asking was possible, I could make you download a multi-gigabyte file just by making you visit my webpage. That wouldn't be a good situation to be in.
If you don't want the user to download and re-upload a file, then you don't want a file input. The other solution you mentioned (a field just containing the URL) sounds perfect for this.
I'm looking for a way to let user upload a config file (text base, no encryption), then parsing that file (either line by line or separating fields by commas,...) to pre-fill textboxes field on the same page using javascript.
Thanks for your help :)
First, you'll have to handle the upload via a ajax upload. Your javascript then can make an ajax call out to get the contents of the HTML file. What exactly are your need beyond this?