使用move_uploaded_file在php中移动文件

时间:2014-06-23 09:42:18

标签: php phpmyadmin

我有一个问题,现在我的所有视频文件都在/videos,现在我想将所有文件移到/videos/2014/05或/ {{}}} ...我的数据库中我有一个现场通话日期(视频时) 已上传)现在如何创建此脚本以制作文件夹videos/2014/06并将所有视频移到那里?

我尝试过一个例子,但没有收到。

/2014/05

1 个答案:

答案 0 :(得分:0)

public function move()
{
    if ( !file_exists(  $this->config->item("multimedia_path") . 'images/'. $today_folders) ){
    $old_umask = umask(0);

    $this->load->database();
    // Assuming mp4_video is your file name
    $videos=$this->db->query("SELECT mp4_video, date FROM videos  ORDER BY date DESC");

    $source = "videos/";

    foreach ($videos as $video) {
        // Load the destination for the video based on the date it was uploaded, assuming your DB wrapper converts date into a DateTime object, if not let me know it's type(eg int because it's a timestamp, or string because it's a mysql datetime, or whatever)
        $destination = $this->config->item("multimedia_path") . 'videos' . $video['date']->format('/Y/m/d/');
        // Again, assuming mp4_video is your filename
        $file = $video['mp4_video'];

        mkdir( $destination, 0777, true);

        if (copy($source.$file, $destination.$file)) {
           $delete[] = $source.$file;
        }
    }

    umask($old_umask);
    foreach ($delete as $file) {
        unlink($file);
    }
}