0

I'm developing a website with Laravel in my localhost (in my local server), and in some part of my project I need to upload some XML files to generate a Excel file with phpexcel api. This is how my work proceed:

1 - I create xml files with forms and store them in my public directory in my projects

2- when I want to upload and use those xml files, I'm just taking the name from input and add them to an url to open the file stored localy ( something like this :)

$xml_tmu=simplexml_load_file($url) or die("Error: Cannot create object");

So my question is this: when I will upload my website in a server, do I need to store my xml files in a database so I can use them after, or they will be created in a public directory in the server (like the same thing in my local server)? And if not, what is the best solution to do so ?

4
  • How you store your data (file/db) is a separate concern. Personally, I wouldn't put uploads in the public directory, instead make a controller that takes the file name and uses fopen() instead of performing an HTTP request to the same server, which is kind of pointless and unnecessary. Then you can pass the contents in to your simple xml. Also, DOMDocument is way better than simple xml, check it out! Commented Sep 18, 2017 at 13:14
  • I think here you don't need to upload xml files as you are already converting them to excel file. And Dp not uploads the file in public directory Commented Sep 18, 2017 at 13:16
  • i undertand now that i don't have to store in public directory, but i need to save my xml file to use them after to generate an excel file, so please ? what is the best way to do it ? Commented Sep 18, 2017 at 13:20
  • Well Jaffery way has defined some best practice on file uploading in this episode you can watch this: laracasts.com/series/whats-new-in-laravel-5-3/episodes/12 Commented Sep 18, 2017 at 13:30

1 Answer 1

1

You don't need to use a database if you don't want to use a database to store files in your server.

If you have an usual Laravel app running on your remote server, you probably have a writable storage folder in the root of your application directory, so you can probably do

$xmlFilename = 'whatevernameyouneedhere.xml';

$xml_tmu = simplexml_load_file($url) or die("Error: Cannot create object");

Storage::put($xmlFilename, $xml_tmu);

And then you can get it back using

$xml = Storage::get($xmlFilename);

It works locally or remotely, if, of course, your storage folder is writable to the webserver user (nginx, apache2, www-data....)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.