这是我的代码:
class ManImportsController extends AppController {
public $uppath;
var $name = 'ManImports';
var $uses = array ('RFupload','ManImport');
var $helpers = array ('Html', 'Session','Time', 'Form', 'Js', 'Javascript','DatePicker','Ajax','IrDependentArray','databaseFields','FileUpload.FileUpload', 'showFields');
var $components = array ('FileUpload.FileUpload','Session','RequestHandler');
var $actsAs = array('FileUpload.FileUpload' => array(
'uploadDir' => $this->uppath, // Primary Upload Path
'forceWebroot' => false, // false, files upload to uploadDir
'fields' => array ('name' => 'name', 'size' => 'size',
'date' => 'date', 'created' => 'created',
'type' => 'type'),
'allowedTypes' => array ('csv' => array('application/csv'),
'xls' =>array('application/vnd.ms-excel'),
'xlsx' =>array('application/vnd.ms-excel')),
'required' => false, // true = errors when file isn't uploaded.
'maxFileSize' => false, // false to turns off maxFileSize
'unique' => true, // true will overwrite files with same name.
'massSave' => true,
'fileNameFunction' => false)); //execute the Sha1 function on a filename before saving it (default false)
public function beforeFilter() {
$this->uppath = $this->get_path();
} // end function beforeFilter
function get_path() {
$mach = gethostname();
if ($mach=='my_machine_ID') {
$path = "C:/home/files/uploads/";
} else {
$path = '/home/files/uploads/';
} // end if $mach
return $path;
} // end function get_path
} // end class ManImportsController
问题是通过正确调用函数/方法“get_path”来正确分配“uploadDir”。我已经尝试了大约 4 种不同的组合,包括 cakePHP 约定和 PHP OOP,但到目前为止没有任何效果。
你看到我在这里缺少什么了吗,你能告诉我正确的称呼方式吗?
我必须在 Linux 机器上部署,但目前需要使用 Win7 开发机器。