PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] PHP download image from url without direct image name

 January 19, 2022     curl, laravel, laravel-5, php, php-5.6     No comments   

Issue

{{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?


Solution

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);


Answered By - Puneet Karajagi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing