dqndc26628 2012-03-06 21:20
浏览 44
已采纳

如何使用zend框架设置上传文件的路径?

i am trying to upload a video and convert it in php using zend framework and i have a bit of a problem with my logic.

i have a directory, locally, that needs to hold the uploaded files:

C:/xampp/htdocs/zend/videos/

fist i need to convert the video then move it in that directory.

For conversion im using something like this:

exec("ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv", $out);

here is a part of my form:

$file = new Zend_Form_Element_File('file');
    $file->setLabel('File')
        ->setRequired(true)
        //->setDestination('/var/www/tmp') use in real life
        ->setDestination('C:/xampp/htdocs/zend/tmp')
        ->addValidator('Size',
                false,
                array('min' => '10kB', 'max' => '100MB'));

when i upload the file it goes to that directory just fine.

Do i need to convert the file in the tmp directory and then move it to my other main one, then delete the original one?

Isn't there a way to hold the original file in a temp directory temporary until it gets converted and then it will automatically delete itself?

I am trying also to use Zend_File_Transfer_Adapter_Http but im a bit confuse on what is the difference in between setDestination and the target from the Rename filter and if there is a need to use it.

i home someone could bring some light into this issue, maybe some best practices.

Thanks

  • 写回答

1条回答 默认 最新

  • dongshou6788 2012-03-06 22:11
    关注

    I am trying also to use Zend_File_Transfer_Adapter_Http but im a bit confuse on what is the difference in between setDestination and the target from the Rename filter and if there is a need to use it.

    setDestination() is deprecated, and the Rename filter should be used instead. If you have a Rename filter set, it will override the destination. Otherwise, there isn't much of a difference. The main difference is that the Rename filter can rename the file, where setDestination keeps the original file name as it was on the user's PC and only moves it to the destination. This could lead to existing files being overwritten or someone smashing another user's file if you don't carefully name them.

    Do i need to convert the file in the tmp directory and then move it to my other main one, then delete the original one?

    Personally, I wouldn't try to convert the file as it is uploaded. While the conversion may be quick in many cases, what happens if a relatively large video was uploaded and it takes an additional 4 minutes to encode the video? You don't want the user hanging there waiting wondering what is happening while the conversion takes place.

    I would upload the files, copy them to a temporary location where they will be converted and then moved to the original location. This adds complexity of course.

    If you want to convert the videos on the fly as they are uploaded, I may not even bother using Zend_File_Transfer_Adapter_Http at all. Instead, use the $_FILES superglobal to access $_FILES['videofile']['tmp_name'] and have ffmpeg convert that file and just write the output to the final destination, or a temp destination and then move it when conversion completes. Files uploaded to PHP are deleted automatically when the request terminates unless you call move_uploaded_file or manually do something to write the temporary file to a permanent location.

    Isn't there a way to hold the original file in a temp directory temporary until it gets converted and then it will automatically delete itself?

    Yes, if you go without Zend_File_Transfer. The uploaded file is automatically in a temporary directory until the PHP request terminates. If you do the conversion on the fly, the original temp file is automatically deleted when PHP finishes.

    Hopefully that clears things up a bit for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题