1 回答
TA贡献1111条经验 获得超0个赞
1.您需要使用pathinfo()来获取文件扩展名。
2.$filename
在你的代码中没有定义,所以它会给你警告,并且扩展检查代码总是会失败。
修改代码如下:
$ftp_server = "myserver";
$ftp_user_name = "myuser";
$ftp_user_pass = "mypass";
$source_file = $_FILES['file']['tmp_name'];
$fileType = $_FILES['file']['type'];
/*get file extension [*/
$fileExt = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
$fileExt = strtolower($fileExt);
/* ] */
$destination_folder = "/public_html/wp/wp-content/plugins/AbonneerProgrammas/FilesUpload";
$destination_file = $destination_folder . "/" . basename($_FILES['file']['name']);
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
$allowed = array('zip', 'rar');
/*use $extension variable to check allowed or not [*/
if(in_array($fileExt, $allowed)) {
//my upload code
}else {
echo "U mag dit type bestand niet uploaden.";
}
/* ] */
- 1 回答
- 0 关注
- 269 浏览
添加回答
举报