I have followed the Odan tutorial to create a REST API with a Mysql DB to serve data in Json format to some clients (VueJs for now).
But I need to use images in my app. I need to send it with my client to my API server, stock them and serve them to the client.
It’s images to illustrate some object (hundreds). Object is a table of my DB with some properties.
So i think I need to store images directly in a directory of my server and store the path in my object table.
But I don’t konw how to do that.
First I tried to serve an existent image form my server to my client (postman to try it) following the image tutorial from Odan
But if switch this line :
// Create image in memory
$image = $this->imageManager->canvas(800, 600, '#719e40');
This command does not work. It’s give me an empty string. I don’t now why because it’s the same line.
With more researches, I find that the getClientFilename() methods send (with a var_dump() : string(14) \"bound sendFile\"\n\"\"
So it’s logical that the pathinfo() methods doesn’t work.
Edit :
I have found the solution : The getClientFileName() methods doesn’t work if we had name property in the FormData javascript object.
The pathinfo function works only for “valid” filenames. You could remove or replace all invalid characters before you use the pathinfo function. Generally, it is never very “safe” to use the client’s filename. So maybe consider a “fallback” to detect the correct extension.
You need only one request for the upload. The response from the POST (image upload) request could return a JSON object with the generated object values.