2017-06-04 21 views
7

Dự án của tôi có hai phầnKhông thể tải tệp từ plugin Wordpress lên máy chủ phụ trợ của symfony qua API?

  • wordpress frontend
  • Symfony backend

Tôi cố gắng để gọi API của dự án symfony backend may từ Wordpress plugin để lưu trữ một số dữ liệu trong backend. tất cả các dữ liệu văn bản đang được lưu nhưng khi tôi đang cố gắng gửi các tập tin hình ảnh chúng không được lưu trong phần phụ trợ. Tôi biết nó là một công việc phức tạp nhưng tôi thực sự đang tìm kiếm giải pháp.

để tải lên hình ảnh chúng ta đang làm theo các bước

  1. chúng ta đang tạm thời tải lên hình ảnh vào thư mục upload Wordpress của chúng tôi
  2. sau đó chúng tôi đang gửi các tập tin trong yêu cầu của chúng tôi trong việc kêu gọi api
  3. symfony backend API nhận yêu cầu và tải lên hình ảnh phù hợp

đây là mã kết thúc trước Wordpress của tôi và biến yêu cầu:

$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); 

yêu cầu cho các api là:

{ ["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]" } 

hình ảnh được thể chất lưu trong thư mục upload Wordpress và cũng được gửi qua api nhưng backend của chúng tôi không được chọn lên các hình ảnh và không tải chúng

đây là mã phụ trợ của chúng ta về 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); 
    } 
} 

Đối với hồ sơ mã này là perfe ctly chạy 2 năm trước nhưng nó đột nhiên ngừng làm việc:

Tôi nhận được lỗi này

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 [] [] 
+0

Bạn có thể hiển thị Front-End 'form' không? –

+0

hình thức kết thúc trước wordpress? – numerah

+0

có, mẫu kết thúc trước –

Trả lời

3

có một lỗi ở '@'.realpath($path) từ php 5.5 và ở trên này được sử dụng curl_file_create(realpath($path)) thay vì '@'. vấn đề được giải quyết

Các vấn đề liên quan