-1

I had problem, when i tried send the big PDF file (42 mb). Has API limit to getting file? My code:

$filename_pdf = $_SERVER['DOCUMENT_ROOT'] . '/test/test_pdf_2.pdf';

$fh_res = fopen($filename_pdf, 'r');

$login = '******';
$password = '*********';
$url = 'http://do.convertapi.com/Pdf2Image';

// Create a CURLFile object
$cfile = new CURLFile($filename_pdf, 'application/pdf', 'test_pdf_2.pdf');
$data = array(
    'File' => $cfile,
    'OutputFormat' => 'jpg',
    'ApiKey' => '******',
    'StoreFile' => 1,
    'Timeout'=>'1200'
);

$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($process, CURLOPT_INFILESIZE, filesize($filename_pdf));
curl_setopt($process, CURLOPT_INFILE, $fh_res);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $login . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 600);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);

My code working with small files. Has API limit to getting file?

Samir
  • 11
  • 1

2 Answers2

2

There are some limitations. In your php.ini file you can find the values. Directly concerned are:

  1. post_max_size
  2. upload_max_filesize
  3. max_file_uploads
  4. max_input_time

You can inspect the values with phpinfo() and simply change them. Here a how to change your configuration: http://php.net/manual/en/configuration.changes.php

This whole thing for sure only applies to your server. You can't check the settings of another server, so its totally possible that the endpoint you're calling will block big files.

Twinfriends
  • 1,972
  • 1
  • 14
  • 34
  • Thank you for answer. My server has this configurations: ```post_max_size = 100M upload_max_filesize = 100M max_file_uploads = 20 max_input_time = 60 ``` – Samir Jul 31 '17 at 09:39
  • @Samir may the `max_input_time` is too short, 1 minute for 42mb is quite fast I think. May you can try to increase it and test it again. But not sure if this will help. – Twinfriends Jul 31 '17 at 09:42
  • This is partially correct. As the file itself is already in the server (as specified in codes in the questions), `upload_max_filesize` and `max_file_uploads` are not really related. As OP is using cURL to transfer the file to target API, the timeout value of cURL has to be changed, or the file transfer will time out. Also, does the target API support uploading files in chunks? Uploading huge file in one shot doesn't make sense at all. – Raptor Jul 31 '17 at 09:59
  • @Twinfriends I increased the limit. Now max_execution_time = 360 – Samir Jul 31 '17 at 10:32
0

You can check in your php.ini files for below lines.

  • upload_max_filesize = 2M
  • post_max_size = 2M
  • max_execution_time
  • file_uploads
  • max_input_time
  • memory_limit

upload_max_filesize : Maximum allowed size for uploaded files

post_max_size : Maximum size of POST data that PHP will accept

max_execution_time : Maximum execution time of each script, in seconds

file_uploads : Whether to allow HTTP file uploads

max_input_time : Maximum amount of time each script may spend parsing request data

memory_limit : Maximum amount of memory a script may consume

Set the desired values for above lines. This will fix your problem.

Sumon Sarker
  • 2,707
  • 1
  • 23
  • 36
  • Спасибо за ответ. Мой сервер имеет следующие конфигурации: `Upload_max_filesize = 100M post_max_size = 100M max_execution_time = 360 file_uploads = on max_input_time = 360 memory_limit = 256M` – Samir Jul 31 '17 at 10:23
  • After saving this configuration, You must restart your Server. @Samir – Sumon Sarker Jul 31 '17 at 10:36
  • I restarted. No working. I think "http://do.convertapi.com/Pdf2Image" has limit to get a file. – Samir Jul 31 '17 at 10:37
  • Try `upload_max_filesize` instead of `Upload_max_filesize` @Samir – Sumon Sarker Jul 31 '17 at 10:40
  • You should debug `phpinfo();` http://php.net/manual/en/function.phpinfo.php , Then you will see, what is the actual configuration in your server. @Samir – Sumon Sarker Jul 31 '17 at 10:42
  • In my configuration is "upload_max_filesize". All correct. – Samir Jul 31 '17 at 10:42