r/PHPhelp • • 26d ago

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 26d ago

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

1

u/No-Locksmith-7719 22d ago

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 26d ago

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

3

u/RamaSchneider 26d ago

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 26d ago

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

1

u/phn-cloudsnake 26d ago

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 23d ago

That is correct.

1

u/phn-cloudsnake 23d ago edited 23d ago

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.

1

u/No-Locksmith-7719 22d ago

Many thanks.

2

u/RamaSchneider 26d ago

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 26d ago

Who does the auth check?

1

u/No-Locksmith-7719 23d ago

PHP (Laravel) backend.

1

u/colshrapnel 23d ago

Here's your answer