开发者

Implementation of Uploadify with Zend Framework

Okay,

I have read, and tried a lot of things on how to implement uploadify with Zend Framework, and I'm probably overlooking something, but I'm completely stuck. It seems my action isn't called.

All the uploadify are placed in one directory inside the public folder.

The upload button is called in a fancybox instance and is loaded from a hidden div on the same page (admin/images/index) through the inline concept of Fancybox.

All the jquery stuff works great, the uploading works fine, and every file is completed. But the files aren't removed to the folder. When testing with the uploadify.php script everything works fine.

There are no errors in the console.

Tested on localhost Tested with Chrome 6.0.4 & Firefox 6.3.6 Tested with uploadify 2.1

This is my jquery init code: (I use loader for the use of jquery scripts)

Removed to keep post readable

I used different things to call the file, but none of them worked:

   Removed to keep post readable

This is the code in my admin/images/upload

    Removed to keep post readable

This is the code used in my bootstrap for the cookie problem:

    Removed to keep post readable

Anybody any clue? I'm completely lost....

==================================== EDIT ========================================

The problem is still that I can't reach the controller action. I have changed some things for easier testing. The current code is as follows: case 'jpg': $validExtension = true; break; case 'jpeg': $validExtension = true; break; case 'gif': $validExtension = true; break; case 'png': $validExtension = true; break; I don't understand why the action isn't called..

Another edit:

Current scripts:

case 'jpg': $validExtension = true; break; case 'jpeg': $validExtension = true; break; case 'gif': $validExtension = true; break; case 'png': $validExtension = true; break;

Creating the upload resources returns in a HTTP error by uploadify.js

I tried several session solutions found on the uploadify forum and more, but that didn't make any difference...

Another edit

I worked further, and adding the resource for upload

$this->acl->add(new Zend_Acl_Resource('upload'));

gave me the html output form the not logged in/ no role script, pointing to the known session issue. I'm goi开发者_如何学Pythonng to try several solutions and will get back if the scripts works.


Oke I fixed the whole thing. I discovered that the upload has to be added as a resource. The flash session problem was fixed with a plugin that can be found here

Note: This is tested localhost only for now

This is how the scripts look:

The index.phtml

<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
    $('#uploaderImages').uploadify({
        'uploader'      : '../../uploadify/uploadify.swf',
        'script'        : '<?php echo $this->baseUrl().'/admin/images/upload'; ?>',
        'cancelImg'     : '../../uploadify/cancel.png',
        'scriptAccess'  : 'always',
        'queueID'       : 'fileQueue',
        'folder'        : '../../uploads/images/original/',
        'multi'         : true,
        'auto'          : true,
    });
});
// ]]></script>

The imageController:

public function uploadAction()
    {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
        $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
        move_uploaded_file($tempFile,$targetFile);
    }

And add the resource in your ACL:

$this->acl->add(new Zend_Acl_Resource('upload'));

If I encounter more problems, or if anybody else does, please let me now, and I will update this question/answer with needed additional info.

Tested in Firefox 3.6 & Chrome 6.0

Edit

The above solution works on a live server, but only on windows. In all browsers from a mac the data doe not get posted. I found the fix as written here: http://slavi.biz/blog/using-uploadify-with-zend-framework-2009-08-30.html to work fine both on windows and mac.


From what I have discovered, I was having some similar issues because the swf and upload.php files weren't in the same directory and directory permissions were off.


I can't see where you're disabling the view renderer. Maybe this is the problem.

If you already have a view called upload or index (based on your edit) does you have a layout? The uploadfy need only a string as output.

So you have to add this lines to your action:

$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

If this doesn't work I sugest you to test on an separated page without zend framework, so that you can know exactly what's going on.

Also, access the page via browser and tell us if it is working without erros (images/index or upload)

Finally, I also sugest you to use firebug and analyze the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜