首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么ConvertAPI不使用PHP

为什么ConvertAPI不使用PHP
EN

Stack Overflow用户
提问于 2018-10-23 13:20:54
回答 1查看 505关注 0票数 1

我正在使用ConvertAPI使用PHP

昨天,我的代码在ConvertAPI .But中正常工作,今天它突然失效,给我错误的操作在0毫秒后超时,0/0字节接收到。我没有改变code.But的一行,我不知道为什么它给了我一个error.please帮助我谁知道这个问题。

我的代码如下:

代码语言:javascript
复制
<!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库

composer需要转换/转化法-php

EN

回答 1

Stack Overflow用户

发布于 2020-11-05 22:12:39

这在linux上对我起了作用。编辑文件:

代码语言:javascript
复制
sudo /etc/resolv.conf 

并粘贴以下内容:

代码语言:javascript
复制
nameserver 208.67.222.222
nameserver 208.67.220.220

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52950196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档