【问题标题】:Why does ConvertAPI not working using PHP library为什么 ConvertAPI 不能使用 PHP 库
【发布时间】:2019-03-27 18:13:27
【问题描述】:

我正在通过 PHP 库 [ConvertAPI] 使用 ConvertAPI

昨天我的代码在 ConvertAPI 中正常工作。但是今天突然它不起作用并给我错误操作在 0 毫秒后超时,收到 0 个字节中的 0 个。我没有更改单行代码。但我不知道为什么它会出错。请帮助我知道这个问题的人。

我的代码如下:

<!DOCTYPE html>
<html>
  <head>
    <title>PHP - Convert API Example</title>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  </head>
  <body>
    <div class="container">
      <form method="POST" action="" enctype="multipart/form-data">
        <div class="form-group">
            <label>Add Image:</label>
            <input type="file" name="file[]" class="form-control" multiple="multiple">
        </div>
        <div class="form-group">
            <button class="btn btn-success">Submit</button>
        </div>
     </form>
    </div>
 </body>
</html>

<?php 
require 'vendor/autoload.php';
use \ConvertApi\ConvertApi;

ConvertApi::setApiSecret('My-secret-key');

if(!empty($_FILES["file"])){
   try {
    if(count($_FILES['file']['name']) > 0){

       $newFileName = $_FILES['file']['name'];
       //Loop through each file
       for($i=0; $i<count($_FILES['file']['name']); $i++) {
       //Get the temp file path
          $tmpFilePath = $_FILES['file']['tmp_name'][$i];
          $fileName = $_FILES['file']['name'][$i];
          $newFileName = substr($fileName, 0 , (strrpos($fileName, ".")));      
         //Make sure we have a filepath
          if($tmpFilePath != ""){   

              //save the filename
              $shortname = $_FILES['file']['name'][$i];
              //save the url and the file
              $filePath = "uploads/".$_FILES['file']['name'][$i];
              //Upload the file into the temp dir
              if(move_uploaded_file($tmpFilePath, $filePath)) {
                 $files[] = $shortname;               
              }
              $result = ConvertApi::convert('jpg', ['File' => $filePath]);
              $final_result = $result->response['Files'][0]['FileName'];
            //echo '<pre>'; print_r($result);
             $result->getFile()->save('uploads/'.$newFileName.'.jpg');        
           }
     }
  }

}
catch (Exception $e) {
  echo "Something else went wrong: " . $e->getMessage() . "\n";
}
}

为此我安装了 PHP 库使用

作曲家需要 convertapi/convertapi-php

【问题讨论】:

  • Operation timed out after 0 milliseconds。也许 API 端点当前处于脱机/关闭状态。您可以寻求支持:convertapi.com/support
  • 我得到了解决方案。我的空闲秒被使用了。所以,它给出了这样的错误。

标签: php converters


【解决方案1】:

这在 linux 上对我有用。 编辑文件:

sudo /etc/resolv.conf 

并粘贴以下内容:

nameserver 208.67.222.222
nameserver 208.67.220.220

将使用 OpenDNS,注释掉文件中现有的域名服务

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    相关资源
    最近更新 更多