我目前正在尝试在localhost上上传.csv文件的上传表单,但是我还没能用它上传文件。这是因为我需要在localhost上chmod一个目录。目前我正在使用它:
$allowed_filetypes = array('.csv');
$max_filesize = 524288;
$upload_path = '/csvfiles/';
$filename = $_FILES['userfile']['name'];
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path)){
$chmod = chmod ($upload_path & "/" & $_FILES, 777);
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)){
echo 'Upload succesful';
}else{
echo 'There was an error during the file upload. Please try again. :('; // It failed :(.
}
} else
die ('You cannot upload to the specified directory, please CHMOD the directory.');
我不确定这行代码需要什么:
$chmod = chmod ($upload_path & "/" & $_FILES, 777);
我的脚本一直在死,目录没有任何反应。
此外,如果您有这类事情的经验,请随意调试! :d
Side note: My OS is RHEL5
提前致谢,
-Max
答案 0 :(得分:3)
1)检查它是否已写入 2)如果不是,请使用exec()来chmod。
if(!is_writable($path)) {
exec("chmod -R 777 $path");
}
// code for uploading.
这段代码可以做得更漂亮,例如将它包装成递归函数但是我会把它留给你:)
答案 1 :(得分:2)
您尝试将$_FILES
数组连接到字符串以创建最终路径为chmod
ded,这可能是问题所在。如果我理解正确,您需要将其更改为:
$chmod = chmod ($upload_path & "/" & $filename, 777);
或
$chmod = chmod ($upload_path & "/" & $_FILES['userfile']['name'], 777);
因此您将文件名附加到$upload_path
。