0
{{my_salesforce_url}}/sfc/servlet.shepherd/document/download/0694U000007w5QyQAI?operationContext=S1

this url content a file with name ine_file.jpg, when run in browser work and download the file direct, but when i try download with php and save the file in local no work

i try with:

file_put_contents(public_path() . "/" . $fileName, fopen($file["url"], 'r'));

and

    file_put_contents(public_path() . "/" . $fileName, file_get_contents($url));

any idea ? How to get a file from url and save the file using php o curl?

pedroooo
  • 563
  • 1
  • 4
  • 17
  • 1
    are you getting an error message? What does file_put_contents and file_get_contents return? – Dimich Sep 15 '20 at 21:15
  • Do you need a login to view that image? Perhaps your PHP need to be authorized to access your sales force content? Maybe you should be looking into the sales force Rest API. – Scuzzy Sep 15 '20 at 21:32

1 Answers1

0

You can try this if you are downloading from a secured server

$options = array(
"ssl" => array(
    "verify_peer" => false,
    "verify_peer_name" => false,
),
);
$image = file_get_contents('www.example.com/image.jpg', false, stream_context_create($options));
$filename = 'filename.jpg';     
$filedir = 'public/uploads/' . $filename;
file_put_contents($filedir, $image);