My project have two Parts
- wordpress frontend
- Symfony backend
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
- we are temporarily uploading images to our Wordpress upload folder
- then we are sending those files in our request in calling api
- symfony backend API is getting the request and uploading the images accordingly
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);
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) "[email protected]" }
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
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 );
}
}
For the record this code was perfectly running 2 years ago but it suddenly stoped working:
I am getting this error
request.INFO: Matched route "curd.api.pass.create.uploads" (parameters: "_format": "json", "_controller": "CogilentPassbookBundleControllerApiController::createpassuploadAction", "_route": "curd.api.pass.create.uploads") [] []
[2017-06-04 04:57:07] security.INFO: Populated SecurityContext with an anonymous Token [] []
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…