无法通过 API 从 Wordpress 插件上传文件到 symfony 后端服务器? [英] Unable to upload file from Wordpress plugin to symfony backend server over the API?

查看:15
本文介绍了无法通过 API 从 Wordpress 插件上传文件到 symfony 后端服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有两个部分

  • wordpress 前端
  • Symfony 后端

我正在尝试从 Wordpress 插件调用 May 后端 symfony 项目的 API 以在后端存储一些数据.正在保存所有文本数据,但是当我尝试发送图像文件时,它们并未保存在后端.我知道这是一项棘手的业务,但我确实在寻找解决方案.

I am trying to calling the API of may backend symfony project from Wordpress plugin to store some data in the backend. all the text data is being saved but when I am trying to send image files they are not being saved in the backend. I know its a tricky business but I am really looking for the solution.

为了上传图片,我们正在执行以下步骤

for uploading images we are doing following steps

  1. 我们暂时将图片上传到我们的 Wordpress 上传文件夹
  2. 然后我们在调用 api 的请求中发送这些文件
  3. symfony 后端 API 正在获取请求并相应地上传图像

这是我的 Wordpress 前端代码及其请求变量:

here is my Wordpress front end code and its request variable:

$localUploadPath  = dirname(__DIR__).DIRECTORY_SEPARATOR.'uploads';
$randomDir  = Helper::randomDirName();
$uploadedAssets = Files::uploadPassAssets( $localUploadPath , $randomDir );
$request = new Request();
$submitedValues = $request->all();
$request->files($uploadedAssets);
$groupArray = $request->getGroups();

//remote files upload
$remoteFiles = array();
foreach($uploadedAssets as $fieldName => $imageFiles){
    $imageWithPath = $localUploadPath.'/'.$randomDir.'/'.$imageFiles; 
    $remoteFiles[$fieldName.'File'] = '@'.realpath($imageWithPath);
}
$client = new ClientApi(PASSBUILDER_ADDPASS_UPLOAD_URL);
$client->setFiles($remoteFiles);
$uploadResponse = $client->getResponse();
$this->rrmdir($localUploadPath.'/'.$randomDir);

对 api 的请求是:

request for the api is:

{ ["appearance_logoNameFile"]=> string(149) "@/home/public_html/ads/wp-content/plugins/passbook-app/uploads/4e1020ee2b0dda294c746b5bb5acc0bd/26f27e532c874b63dca651dec4553b20ca237a44.png" ["appearance_eventTicketStripFile"]=> string(149) "@/home/public_html/ads/wp-content/plugins/passbook-app/uploads/4e1020ee2b0dda294c746b5bb5acc0bd/7354f12e6d185eee8142268b32eea6a055036d35.png" ["generalid"]=> string(32) "4ba11ffe3f2b8a46626632b48b38fcaf" ["pass_id"]=> int(198) ["email"]=> string(17) "sample@unknown.com" }

图像物理保存在 Wordpress 上传文件夹中,也通过 api 发送,但我们的后端没有提取图像,也没有上传它们

images are physically saved in the Wordpress upload folder and also being sent through api but our backend is not picking up the images and are not uploading them

这是我们的 symfony 后端代码:

here is our backend code of symfony:

public function createpassuploadAction(Request $request){

    $data = $request->request->all();
    $helper = $this->get('passbook.passhelper');
    $webDir = $helper->webDir;

    $passId = $data['pass_id'];
    $userEmail = $data['email'];
    $generalid = $data['generalid'];

    $filesResult = array();
    $filesBag = $request->files->all();
    foreach ($filesBag as $file){
        $filename = $file->getClientOriginalName();
        $filesResult []=  array(
            'path' => $file->getPathname(),
            'url'  => 'ddd'
        );
        $src    =  $webDir.'/upload/'.$passId.'/';
        $file->move( $src ,$filename );
    }
}

根据记录,这段代码在 2 年前运行良好,但突然停止工作:

For the record this code was perfectly running 2 years ago but it suddenly stoped working:

我收到此错误

request.INFO: Matched route "curd.api.pass.create.uploads" (parameters: "_format": "json", "_controller": "Cogilent\PassbookBundle\Controller\ApiController::createpassuploadAction", "_route": "curd.api.pass.create.uploads") [] []
[2017-06-04 04:57:07] security.INFO: Populated SecurityContext with an anonymous Token [] []

推荐答案

the there was an error at '@'.realpath($path) from php 5.5 and above this is used curl_file_create(realpath($path)) 而不是 '@'.问题解决

there was an error at '@'.realpath($path) from php 5.5 and above this is used curl_file_create(realpath($path)) instead of '@'. problem solved

这篇关于无法通过 API 从 Wordpress 插件上传文件到 symfony 后端服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆