@Nikolays93
Web-разработчик

Как отдебажить input? Как отправить себе файл в input?

Скрипт принимает файл от 1C УТ кодом
$input_file = fopen( "php://input", 'r' );
$temp_file  = fopen( $temp_path, 'w' );
stream_copy_to_stream( $input_file, $temp_file );


Хотелось бы отдебажить эту (и последующую) часть кода, возможно написать юнит тесты. Но вот вопрос, как самостоятельно отравить скрипту файл чтобы он попал в php://input

Пробовал следующее, создает пустой файл (в php://input ничего не приходит).
<?php

if  (!in_array  ('curl', get_loaded_extensions())) {
    exit("CURL is NOT installed on this server");
}

$path = __DIR__ . '/curl.zip';
var_dump(is_file($path) && is_readable($path)); // true
$cFile = new \CURLFile($path, mime_content_type($path), basename($path));
$postData = ['file' => $cFile];

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'pass');
curl_setopt($ch, CURLOPT_URL, 'http://php.test/get.php');
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HEADER, false);
// curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$res = curl_exec($ch);
curl_close($ch);
  • Вопрос задан
  • 49 просмотров
Решения вопроса 1
$input_file = fopen( "php://input", 'r' );
$temp_file  = fopen( $temp_path, 'w' );
stream_copy_to_stream( $input_file, $temp_file );


Кто мешает вместо php://input указать путь к сущесвующему файлу и с ним тестить последующие шаги?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы