我想将excel文件从一个文件夹移动到另一个文件夹,我使用了以下代码行
$approve_employee_id = $this->input->post('approve_employee_id');
$approve_month_id = $this->input->post('approve_month_name');
$approve_year_name = $this->input->post('approve_year_name');
$approve_employee_username = $this->input->post('approve_employee_username');
$folder_name = $approve_month_id.$approve_year_name;
rename(".files/".$folder_name."/un_approved/".$approve_employee_username, ".files/".$folder_name."/approved/".$approve_employee_username);
我继续从系统中收到以下错误:
A PHP Error was encountered
Severity: Warning
Message: rename(.files/January2013/un_approved/HS0103,.files/January2013/approved/HS0103): The system cannot find the path specified. (code: 3)
Filename: controllers/time_sheet.php
Line Number: 279
我的文件夹树如下:
已审核C:\xampp\htdocs\timesheet\files\January2013\approved
,未批准<{1}}
请告知最佳实施方法?
答案 0 :(得分:0)
也许您应该使用&#34; ./files
&#34;而不是&#34; .files
&#34; ...?
但是,我建议将数据文件的位置与php脚本的位置分开......所以,我应该这样做:
...
$basedir = $_SERVER['DOCUMENT_ROOT'] . "/timesheet/files/$folder_name";
rename("$basedir/un_approved/$approve_employee_username", "$basedir/approved/$approve_employee_username);
当您应该将代码部署到不同的Web服务器上时,这种方法可以让您的生活更轻松,例如......
答案 1 :(得分:0)
我只是坚持完整的道路,因为它让它更容易理解......
例如
dirname(__FILE__).'/files/etc/etc/path.yourfile';
你可以通过
上到树上dirname(dirname(__FILE__)).'/files/etc/etc/path.yourfile'; and so on
你可以试试这个......
$files_folder = dirname(__FILE__); //or go up as required.
然后
rename($files_folder."/".$folder_name."/un_approved/".$approve_employee_username, $files_folder."/".$folder_name."/approved/".$approve_employee_username);