xamppでは問題ないのですがエックスサーバーで管理画面から商品登録しようとするとjsonエラーになります。
原因がわからず教えていただけると助かります。
ec cube バージョン4.03
phpバージョン 7.2
product.twig
1var count_add = {{ form.add_images|length|default(0) }}; 2 $('#{{ form.product_image.vars.id }}').fileupload({ 3 url: "{{ url('admin_product_image_add') }}", 4 type: "post", 5 sequentialUploads: true, 6 dataType: 'json', 7 dropZone: $('#upload-zone'), 8 done: function(e, data) { 9 $('.progress').hide(); 10 $.each(data.result.files, function(index, file) { 11 var path = '{{ asset('', 'temp_image') }}' + file; 12 var $img = $(proto_img.replace(/__path__/g, path)); 13 var $new_img = $(proto_add.replace(/__name__/g, count_add)); 14 $new_img.val(file); 15 $child = $img.append($new_img); 16 $('#thumb').append($child); 17 count_add++; 18 }); 19 hideThumbnail(); 20 updateSortNo(); 21 }, 22 fail: function(e, data) { 23 alert("{{ 'admin.common.upload_error'|trans }}"); 24 }, 25 always: function(e, data) { 26 $('.progress').hide(); 27 $('.progress .progress-bar').width('0%'); 28 }, 29 start: function(e, data) { 30 $('.progress').show(); 31 }, 32 acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 33 maxFileSize: 10000000, 34 maxNumberOfFiles: 10, 35 progressall: function(e, data) { 36 var progress = parseInt(data.loaded / data.total * 100, 10); 37 $('.progress .progress-bar').css( 38 'width', 39 progress + '%' 40 ); 41 }, 42 processalways: function(e, data) { 43 if (data.files.error) { 44 alert("{{ 'admin.common.upload_error'|trans }}"); 45 } 46 } 47 }); 48 // 画像アップロード 49 $('#file_upload').on('click', function() { 50 $('#{{ form.product_image.vars.id }}').click(); 51 });
ProductController.php
1 /** 2 * @Route("/%eccube_admin_route%/product/product/image/add", name="admin_product_image_add", methods={"POST"}) 3 */ 4 public function addImage(Request $request) 5 { 6 if (!$request->isXmlHttpRequest()) { 7 throw new BadRequestHttpException(); 8 } 9 10 $images = $request->files->get('admin_product'); 11 12 $allowExtensions = ['gif', 'jpg', 'jpeg', 'png']; 13 $files = []; 14 if (count($images) > 0) { 15 foreach ($images as $img) { 16 foreach ($img as $image) { 17 //ファイルフォーマット検証 18 $mimeType = $image->getMimeType(); 19 if (0 !== strpos($mimeType, 'image')) { 20 throw new UnsupportedMediaTypeHttpException(); 21 } 22 23 // 拡張子 24 $extension = $image->getClientOriginalExtension(); 25 if (!in_array(strtolower($extension), $allowExtensions)) { 26 throw new UnsupportedMediaTypeHttpException(); 27 } 28 29 $filename = date('mdHis').uniqid('_').'.'.$extension; 30 $image->move($this->eccubeConfig['eccube_temp_image_dir'], $filename); 31 $files[] = $filename; 32 } 33 } 34 } 35 36 $event = new EventArgs( 37 [ 38 'images' => $images, 39 'files' => $files, 40 ], 41 $request 42 ); 43 $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_ADD_IMAGE_COMPLETE, $event); 44 $files = $event->getArgument('files'); 45 46 return $this->json(['files' => $files], 200); 47 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。