Click here to Skip to main content
15,942,094 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..I have to download an image in a weblink to my local folder using php. Below is the program. I could successfully download the image , but when i try to open it is showing the file has been damaged.Below is the code snippet




$URL = 'http://10.251.13.7/gtz/temp3.php/download.png'; // Like "http:// ...."
$FileToSave = 'uploads/download.png'; // Like "/home/.." or "C:/..."
$Content = file_get_contents($URL);
file_put_contents($FileToSave, $Content);

What I have tried:

$URL = 'http://10.251.13.7/gtz/temp3.php/download.png'; //  Like "http:// ...."
$FileToSave = 'uploads/download.png';     //  Like "/home/.." or "C:/..."
$Content = file_get_contents($URL);
file_put_contents($FileToSave, $Content);
Posted
Comments
Richard Deeming 23-Oct-18 8:24am    
Are you trying to save the file on your server, or on the user's computer?

Your PHP code is running on the server, and has no access to the user's file system.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900