0

I am trying to put this cURL command in PHP, but it doesn´t seem to work yet.

I want to post a SRT file to https://atelier.u-sub.net/srt2vtt/index.php because that website converts the SRT to a VVT file. I want to save the output of the website (the VVT file) to a file on my server. When I run the cURL command on my Linux server, it outputs the VVT file (so that works).

Command:

curl --form "subrip_file=@Stranger.Things.S01E08.720p.WEBRip.x264-SKGTV.srt" https://atelier.u-sub.net/srt2vtt/index.php

My PHP code:

$request = curl_init('https://atelier.u-sub.net/srt2vtt/index.php');

// send a file
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
  'subrip_file' => '@' . realpath('Stranger.Things.S01E08.720p.WEBRip.x264-SKGTV.srt')
));

// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);

// close the session
curl_close($request); 
Calvin
  • 347
  • 1
  • 4
  • 18
  • Do you get any errors? Are you sure the srt file exists in the same location your php file runs from? – Dekel Jul 17 '16 at 14:04
  • @Dekel No errors and yes. This website (https://atelier.u-sub.net/srt2vtt/index.php) does display on my page, but that shouldn´t happen of course, I want the converted file. – Calvin Jul 17 '16 at 14:19
  • I just tried to run the code and everything seems to work just fine. What version of PHP are you using? And please add `error_reporting(E_ALL);` in order to view all the errors you have. – Dekel Jul 17 '16 at 14:37
  • @Dekel Does it return the VVT file as output on your end? – Calvin Jul 17 '16 at 15:35
  • @Dekel Php 5.6.20 & already added error_reporting(E_ALL); ini_set('display_errors', 1); – Calvin Jul 17 '16 at 15:35
  • Yes, it does. I'm uploading a valid `.srt` file and the output is `vtt` file. – Dekel Jul 17 '16 at 15:37
  • As the site states, it uses an open-source library internaly. Consider using it directly instead of doing http-requests and waiting for the other server to do do your work. – Al.G. Jul 17 '16 at 17:40
  • 1
    Since you are using php 5.6, check this: http://stackoverflow.com/questions/25934128/curl-file-uploads-not-working-anymore-after-upgrade-from-php-5-5-to-5-6 – Dekel Jul 17 '16 at 20:18
  • Possible duplicate of [Convert command line cURL to PHP cURL](https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl) – Anuj TBE Jul 12 '17 at 11:22

0 Answers0