私はmagentoでuploadifyを実装しようとしています。Magento の私の phtml テンプレートには次のものがあります。
<script type="text/javascript">
( function($) {
$(function() {
$('.uploadify').uploadify({
'swf' : 'uploadify.swf',
'uploader' : '<?php echo Mage::helper("adminhtml")->getUrl('*/index/upload') ?>',
'auto' : true,
});
});
} ) ( jQuery );
</script>
アップロード アクションは次のようになります。
public function uploadAction()
{
$targetFolder = '/uploadify/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
}
これは機能していません:(
アップロード アクション内のスクリプトは、uploadify.php のスクリプトとまったく同じです。アップローダー オプションを uploadify.php に変更すると、機能します ('uploader' : 'uploadify.php')。
すべてのヘルプは大歓迎です。