V
V
Vladimir2017-03-31 10:17:31
1C-Bitrix
Vladimir, 2017-03-31 10:17:31

How to write a file to a specific directory in Bitrix?

Hello!
A question. The file is saved to the folder from which the script is called.
When trying to specify a different path, the file is not saved anywhere.
Here is the code

function GetImageByURL($url,$sid) { 
    //$path="/wav/".$sid . ".wav";
    $path=$sid . ".wav";
    $opts = array(CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10); 
    $ch = curl_init(); 
    curl_setopt_array($ch, $opts); 
    $result = curl_exec($ch);
    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200 ) { 
        $file = $path;
        file_put_contents($file, $result);
    } 
    curl_close($ch); 
    return $path;
}

How can I save the file to the directory I need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Shaklein, 2017-03-31
Portev @Vladimir Portev

try specifying full let
$_SERVER["DOCUMENT_ROOT"]

function GetImageByURL($url,$sid) { 
    $path=$_SERVER["DOCUMENT_ROOT"]."/wav/".$sid . ".wav";
    //$path=$sid . ".wav";
    $opts = array(CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10); 
    $ch = curl_init(); 
    curl_setopt_array($ch, $opts); 
    $result = curl_exec($ch);
    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200 ) { 
        $file = $path;
        file_put_contents($file, $result);
    } 
    curl_close($ch); 
    return $path;
}

and check folder permissions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question