亲爱的朋友们,这是一个简单的上传文件并将文件名插入数据库的脚本,为什么这不起作用?它只是上传文件并发送文件名到db,即使经过验证。请帮助为什么这个php文件上传验证脚本不工作?
<?php
//file validation starts
//split filename into array and substract full stop from the last part
$tmp = explode('.', $_FILES['photo']['name']);
$fileext= $tmp[count($tmp)-1];
//read the extension of the file that was uploaded
$allowedexts = array("png");
if(in_array($fileext, $allowedexts)){
return true;
}else{
$form_error= "Upload file was not supported<br />";
header('Location: apply.php?form_error=' .urlencode($form_error));
}
//file validation ends
//upload dir for pics
$uploaddir = './uploads/';
//upload file in folder
$uploadfile = $uploaddir. basename($_FILES['photo']['name']);
//insert filename in mysql db
$upload_filename = basename($_FILES['photo']['name']);
//upload the file now
move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
// $photo value is goin to db
$photo = $upload_filename;
哪部分不工作?你会得到什么样的错误或行为? – mkoistinen 2010-09-20 10:34:10
是否有错误讯息? – piddl0r 2010-09-20 10:34:59
看来你的文件扩展名检测失败。见:http://stackoverflow.com/questions/3179294/how-to-find-the-extension-of-an-image-from-path-in-php/3179305#3179305 – fabrik 2010-09-20 10:39:22