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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动