S
S
smoln2015-09-23 12:43:40
PHP
smoln, 2015-09-23 12:43:40

How to download an image file from an external link?

Hello everyone, here is the code

$picture_url="Ссылка на файл";
$item_id="id товара";
$item_name="название товара";
$uploaddir = "../images/item/$item_id";
    if (!is_dir($uploaddir)){
        mkdir($uploaddir,0755);
      }// if is_dir	 

        $ext = getExtension($big_photo);

        $bphoto = "".(translit($item_name))."-b$item_id.".$ext;
        $sphoto = "".(translit($item_name))."s$item_id.".$ext;
        
        $ubphoto = $uploaddir."/".$bphoto;
        $usphoto = $uploaddir."/".$sphoto;
      
    $uploadfileb = $uploaddir."/".$bphoto;
  $uploadfiles = $uploaddir."/".$sphoto;
// Копируем файл в files
file_put_contents($uploadfileb, file_get_contents($picture_url));
file_put_contents($uploadfiles, file_get_contents($picture_url));

in fact, you need to upload a picture to the hosting knowing the link to the picture, but for some reason the file is not loaded, the file itself is created in the folder but weighs 0 mb, where is the error in the code, maybe I didn’t add this ..
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2015-09-23
@mytmid

file_get_contents() returns the contents of a file in a string

php.net/manual/en/function.file-get-contents.php
----
use file ( ... )
php.net/manual/en/function.file.php

S
smoln, 2015-09-23
@smoln

Everything worked, as a result, the hosting settings were blocking file_get_contents.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question