I'm working with two different APIs trying to transfer documents from one services to another. So far, the API has been kind of clunky to work with, but I was getting it to work, until now with the documents problem. Here is what I have to do:
1. I need to get the url of the document from the one service (which I have done).
2. Download it to my own servers to a folder called filesToUpload (which I have created).
3. Transfer it to the other services (which I have done with a document already on my servers.)
So as you can see, the problem isn't transferring it to the other service, the real problem is downloading it to my own servers. Here is what I have tried:(the $doc['url'] is the response from the one server, and I have confirmed that the url supplied is an existent document)
$fileToPost = str_replace(" ", "+", $doc["url"]);
$fileName = strchr($fileToPost, "-");
$fileName = substr($fileName, 1);
file_put_contents("/api/ricochet-clean/filesToUpload/$fileName", fopen($fileToPost, 'r'));
Here is my error message:
file_put_contents(/api/ricochet-clean/filesToUpload/uploaded-leads.s3.amazonaws.com/219-2018-06-10-10-19-04-Assign6.docx): failed to open stream: No such file or directory in <b>/Applications/XAMPP/xamppfiles/htdocs/SoftwareAPIs/api/ricochet-clean/index.php</b> on line <b>191</b><br />
In the file_put_contents()
function call, I have tried the /api/ricochet-clean/filesToUpload/$fileName
absolute path and I have also tried a relative path of filesToUpload/$fileName
.
I saw this question: file_put_contents: Failed to open stream, no such file or directory
The answer to this was the developer hadn't created the directory he was trying to download the file to, that isn't my problem because I've confirmed I created the directory AND it is spelled the same both places.
What am I missing here?