我的项目分为两个部分
对于上传图片,我们正在执行以下步骤:
- Wordpress前端
- Symfony后端
对于上传图片,我们正在执行以下步骤:
- 我们将图片临时上传到Wordpress上传文件夹中
- 然后我们在调用api时将这些文件发送到我们的请求中
- Symfony后端API收到请求并相应地上传图像
$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 的请求为:
{ ["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发送,但是我们的后端无法识别这些图片并未将其上传。
以下是我们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 );
}
}
记录一下,这段代码两年前完美运行,但突然间停止工作:
我遇到了这个错误:
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 [] []
foreach ($request->files as $file){
这段代码吗? - Imanali Mamadiev