我有一个问题,现在我的所有视频文件都在/videos
,现在我想将所有文件移到/videos/2014/05
或/ {{}}} ...我的数据库中我有一个现场通话日期(视频时)
已上传)现在如何创建此脚本以制作文件夹videos/2014/06
并将所有视频移到那里?
我尝试过一个例子,但没有收到。
/2014/05
答案 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);
}
}