Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JacDev's avatar

Best way to upload client XML files to Laravel Application? (Any thoughts)

Hello,

I have a problem. I have build a website and now I'd like to get information from clients. The client has a local application that is generating XML files in a certain directory. That directory has to be monitored and the XML data passed to the laravel application. That data needs to be imported (I have the DTD's) and that data then needs to be visible in the Laravel application. I think the following problems are here:

  1. There is no way to monitor a client directory from a browser, right? (Due to securty and I don't want to use Java. Only HTML and/or javascript (framework).
  2. Since that is not possible I probably have to write a client application that will do the file monitoring.
  3. Grabbing the data will not be that difficult. I am only thinking how I should forward it to the web application.
  • I cannot run anything on the webserver (shared hosting)
  • What would be the best way to parse an XML to see if it fullfills the DTD. Can that be done easily? (Otherwise I just skip that and assume XML files are correct, but rather be sure).

Any thoughts, comments or tips are welcome.

0 likes
2 replies
lostdreamer_nl's avatar
  1. You're correct, a browser has no permissions to access the user's drive

  2. Yes, a separate program is needed (This could still be in PHP and running in commandline)

  3. Using your preferred programming language, you will have to POST the file to the server (so it's like uploading it through a form as far as the server is concerned), and setup a laravel POST route to accept an uploaded file and store it on the server.

  4. XML Parsing / validation:

$doc = new \DOMDocument();
$doc->load($filePath);

if(!$doc->schemaValidate( $pathToXsd)) {
     // error handling here....
}

http://php.net/manual/en/domdocument.schemavalidate.php

2 likes
JacDev's avatar

Thanks for your reply.

  1. Too bad.
  2. Didn't think about this. Thanks, I'll consider (although I am not sure if that is best option. I am not sure if php locally can monitor directories easy and move files and such).
  3. Yeah uploading the whole file directly would be smarter. I was thinking about parsing it locally and then posting only the values. But this is much smarter.
  4. Thanks.

Well you helped me a lot! Thanks!

Please or to participate in this conversation.