r/PHPhelp • • Oct 22 '26

FIle uploads

Who should deal with the file uploads POST routes, front facing PHP script or Node.js? If PHP script handles the GET request and shows the form, then, who should place the file inside the node's directory, the PHP script or the Node script?

Node.js script is tasked with processing the uploaded file, but not sure if it should handle the actual file upload and placing.

2 Upvotes

13 comments sorted by

5

u/SamMakesCode Oct 22 '26

You generally want to use node.js or PHP for backend code. Not both.

1

u/No-Locksmith-7719 Oct 26 '26

The entire front-facing website is built in Laravel, and some of the services are consumed through a dedicated control panel. Laravel handles this part quite well. Then, there are some background services written in Node that do other work. So, we are trying to connect the two, but not sure which is the optimal path.

2

u/colshrapnel Oct 22 '26

In those days of vibe-coding you will see even weirder combinations...

3

u/RamaSchneider Oct 22 '26

I'm somewhat confused as PHP and Node.js are very different server processes. Are you trying to run the two on the same process?

1

u/No-Locksmith-7719 Oct 22 '26

As separate processes. PHP talks to, hands over the file to Node service.

1

u/phn-cloudsnake Oct 22 '26

Am I correct to assume you have the php side handling the website as a sort of SSR engine and a node.js API in a sort of micro service architecture?

1

u/No-Locksmith-7719 Oct 25 '26

That is correct.

1

u/phn-cloudsnake Oct 25 '26 edited Oct 25 '26

When using laravel, I think this is a bit of an anti-pattern. Let Laravel handle this. Then if other systems need the data, pull it from the DB / file system or whatever it is that holds the data. Of course that would be the rainbows and sunshine scenario. If that’s not possible due to whatever business constraints, I think the node api is where this endpoint belongs.

2

u/RamaSchneider Oct 22 '26

I'm still confused (but that's not really all that strange) - what is the purpose for using the two separate systems? Is there a reason you can't directly upload to the Node.js stuff?

Hard to suggest with a lot of unknowns, but I'd say off the cuff that if you're receiving the files in PHP then you should just handle everything there. I don't like over complicating things for myself.

2

u/colshrapnel Oct 22 '26

Who does the auth check?

1

u/No-Locksmith-7719 Oct 25 '26

PHP (Laravel) backend.

1

u/colshrapnel Oct 25 '26

Here's your answer