php文件下载怎么写啊?第一次做这个,所以不知道怎么做了,在php页面
<th>上传文件</th>
<td>
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
</td>然后用move_uploaded_file方法将文件放到项目里的upload文件夹下($path = '/upload/documents/'.time();)在那个php页面里有 输入几个text框,然后就是 上传文件 一个text 旁边是一个Browse按钮,然后点击页面的保存的话,就会将上传文件保存到上面的项目upload文件夹下。但我想在点击browse按钮,然后选择文件之后,这个文件象征性的在页面中显示,就像很多邮箱里上传文件之后那样,然后再点击页面中的保存按钮,就上传到那个文件夹下,这个我不会以上是添加内容的页面,但我在编辑这个页面的时候,那个已经上传的文件怎么显示,并且下载啊? 因为在编辑页面中也只有 一个text和旁边的browse按钮。就是下载的功能也不知道怎么做下去了。下载该怎么做?网上查了点,说是什么直接点击链接(这个链接写在哪里,怎么写)文件的路径。
<th>上传文件</th>
<td>
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
</td>然后用move_uploaded_file方法将文件放到项目里的upload文件夹下($path = '/upload/documents/'.time();)在那个php页面里有 输入几个text框,然后就是 上传文件 一个text 旁边是一个Browse按钮,然后点击页面的保存的话,就会将上传文件保存到上面的项目upload文件夹下。但我想在点击browse按钮,然后选择文件之后,这个文件象征性的在页面中显示,就像很多邮箱里上传文件之后那样,然后再点击页面中的保存按钮,就上传到那个文件夹下,这个我不会以上是添加内容的页面,但我在编辑这个页面的时候,那个已经上传的文件怎么显示,并且下载啊? 因为在编辑页面中也只有 一个text和旁边的browse按钮。就是下载的功能也不知道怎么做下去了。下载该怎么做?网上查了点,说是什么直接点击链接(这个链接写在哪里,怎么写)文件的路径。
ob_clean();
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, max-age=0, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: post-check=0, pre-check=0', false);
header('Cache-Control: private');
header('Content-Transfer-Encoding: none');
header('Content-Disposition: attachment; filename='.$filename.'');
header('Content-Type: '.$content_type.'; name="'.$filename.'"');
echo file_get_contents($path);
exit;
}
该页面中选择好文件之后,就会在input type="file"的框里有要上传的文件的路径名,然后点击保存按钮的话,整个文件就保存到指定路径上。
我想要的是当我选择好要上传的文件之后,希望这个上传的文件能够想邮箱当中的那样,选择好了,就在旁边有要上传的文件名(加后缀的那种,就是邮箱里添加附件中上传完文件之后的样子,但我的程序里看不到这些,选择好要上传的文件之后,只有在text框里有上传文件的路径和名字)。还有就是我类似地执行了很多添加页面(每个页面添加一个文件),之后,当我在编辑页面(和添加页面用同一个页面)的时候,怎么判断哪个上传文件是哪个页面上传的。
只要是因为第一次做这个,所以不是很懂,网上说用什么header方法,但我第一次做,不知道怎么用。
<tr>
<th>上传文件</th>
<td>
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
<a href="hr/doc/download/">DownLoad AttachFile</a>
</td>
</tr>$document_filename = $_FILES['document_file']['name'];
if(is_uploaded_file($document_file['tmp_name']))
{
if(in_array($document_file['type'], array( 'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'text/csv')
))
{ $path = '/upload/documents/'.$document_filename;
if(file_exists(PROJECTPATH.'hosts/www'.$path) == TRUE)
{
@chmod(PROJECTPATH.'hosts/www'.$path, 0777);
@unlink(PROJECTPATH.'hosts/www'.$path);
if(move_uploaded_file($document_file['tmp_name'], PROJECTPATH.'hosts/www'.$path)){}
}
else
{
if(move_uploaded_file($document_file['tmp_name'], PROJECTPATH.'hosts/www'.$path)){}
}
}
}
http://gw.accommate.dev/hosts/www/upload/documents/first
http://gw.accommate.dev/hosts/www/upload/documents/file