Можно ли получить поток файлов, используя exec с другой командой?

1

Мне нужен поток файлов.

Например

private function faviconFoundExec($url)
{
    exec('wget ' . $url . ' -O ../favicons/test.jpg 2>&1', $output);
}

сохранит фактический файл, но мне нужен поток файлов, то же самое, что file_get_contents вернется, как file_get_contents ниже.

private function faviconFoundGet($url)
{
    return @file_get_contents( $url );
}

Я смотрю на passthru, но документация немного неясна.

  • 0
    Как насчет fopen () php.net/manual/en/function.fopen.php . Или вы ищете файл ()? Чего не хватает в file_get_contents ()?
  • 0
    По какой причине вы должны использовать exec и не использовать встроенные функции обработки файлов?
Показать ещё 1 комментарий
Теги:
download

1 ответ

1

Вы можете получить поток из команды с proc_open

$descriptorspec = array(
    0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
    1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
    2 => array("pipe", "w")    // stderr is a pipe that the child will write to
);

$cmd = 'wget -qO- ' . $url;

$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());

$contents = stream_get_contents($pipes[1]);

fclose($pipes[1]);

// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
proc_close($process);
  • 0
    @cadegalt ты прав. Я исправил wget, чтобы он указывал на стандартный вывод. Только что проверил и все работает
  • 0
    gnu.org/software/wget/manual/wget.html
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню