我想要实现的是我想创建一个链接,用于在网页上的某个地方下载文件,用于通过php发送新上传的文件
php代码看起来像这样:
`
$target_path = "uploads/";
$filename = $_FILES['userfile']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = array('gp5','gp4' ,'gp3');
$filename = $_FILES['userfile']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
echo 'not a valid file extension';
}
else {
$target_path = $target_path . basename( $_FILES['userfile']['name']);
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['userfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
}
`
答案 0 :(得分:0)
假设目标路径位于web root
中的某个位置,您可以在success
的{{1}}语句的if
部分内执行此操作:
move_uploaded_file
修改
原来你想要的是上传文件的列表:
echo '<a href="'.$target_path.'">'.$file.'</a>';
编辑:从评论中,您希望所有内容都在一个页面中:
将upload.php和example.html合并到example.php中。让表单提交给自己。这样你就不需要去另一页了。