我通过以这种方式将其路径存储在mysql中来上传文件:
if(isset($_FILES['filefield']))
{
$file = $_FILES['filefield'];
$file_name = $file['name'];
$file_size = $file['size'];
$file_type = $file['type'];
$file_tmpname = $file['tmp_name'];
$upload_dir = "C:/xampp/htdocs/intranet/www/public/uploads/";
$ext_str = "gif,jpg,jpeg,mp3,tiff,bmp,doc,docx,ppt,pptx,txt,pdf";
$allowed_extensions=explode(',',$ext_str);
$max_file_size = 10485760;
$ext = substr($file['name'], strrpos($file['name'], '.') + 1);
if (!in_array($ext, $allowed_extensions))
echo "only".$ext_str." files allowed to upload";
if($file['size']>=$max_file_size)
echo "only the file less than ".$max_file_size."mb allowed to upload";
$path = $upload_dir.$file_name;
if(move_uploaded_file($file_tmpname, $upload_dir.$file_name))
ORM::factory('files')->uploadFile($teacher_id, $file_name, $file_size, $file_type, $path);
else
echo "The file cant moved to target directory.";
}
然后我怎样才能通过它的路径下载这个文件?当然,如果我的上传代码是正确的。