使用Move_上传的文件在php中移动文件
我有一个问题,现在我的所有视频文件都在使用Move_上传的文件在php中移动文件,php,phpmyadmin,Php,Phpmyadmin,我有一个问题,现在我的所有视频文件都在/videos中,现在我想将我的所有文件移动到/videos/2014/05或/videos/2014/06…在我的数据库中,我有一个字段调用日期(当视频 已上载)现在如何创建此脚本以制作文件夹/2014/05,并将所有视频移动到那里 我试过一个例子,但没有收到 public function move() { $today_folders = date('Y') .'/'. date('m'). '/' ;
/videos
中,现在我想将我的所有文件移动到/videos/2014/05
或/videos/2014/06
…在我的数据库中,我有一个字段调用日期(当视频
已上载)现在如何创建此脚本以制作文件夹/2014/05
,并将所有视频移动到那里
我试过一个例子,但没有收到
public function move()
{
$today_folders = date('Y') .'/'. date('m'). '/' ;
if ( !file_exists( $this->config->item("multimedia_path") . 'images/'. $today_folders) ){
$old_umask = umask(0);
mkdir( $this->config->item("multimedia_path") . 'videos/'. $today_folders, 0777, true );
umask($old_umask);
$this->load->database();
$articles=$this->db->query("SELECT *FROM videos ORDER BY date DESC");
$source = "videos/";
$destination = "videos/".$today_folders;
foreach ($articles as $file) {
if (in_array($file, array(".",".."))) continue;
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
foreach ($delete as $file) {
unlink($file);
}
}
stackoverflow不是你的个人代码猴子小组,粘贴你的代码,也许社区可以帮助你我编辑了我的问题…你没有正确访问结果数组,你的视频表中有哪些列?id title mp4\U videodate@user3744761哪些列是您的文件名?我想猜猜mp4\U视频?我在这行有个错误:$destination=$this->config->item(“多媒体路径”)。'视频'$视频['date']->格式('/Y/m/d/');对非对象调用成员函数format(),这是因为您的数据库包装器没有转换为datetime对象,它的类型是什么,就像我在这行上面的评论中问的那样?但是有一个远程视频,我有504个网关超时,如果你在浏览器中运行此操作并获得超时,请尝试将超时设置为无限:
set\u timeout(0)代码>或者,如果您的主机受到限制而无法执行此操作,我将看看如何跨多个页面加载(即每页处理100次,并连续重新加载页面,直到全部完成)。
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);
}
}