语言: PHP /使用Class Upload by Colin Verot
关于:多次上传
下面的代码已经上传文件了,它有效... ...
问题:我无法弄清楚如何获取文件名扩展名 。
(在下面的评论中,我已指定我的问题区域在哪里......)
// CONNECTION TO DATABASE HERE...
// INCLUDE UPLOAD CLASS LIBRARY
include (dirname(__FILE__).'/lib/class.upload.php');
$files = array();
foreach ($_FILES['fileupload'] as $k => $l)
{
foreach ($l as $i => $v)
{
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
$imagename = $_FILES['fileupload']['name'];
}
}
foreach ($files as $file) {
// THIS IS MY PROBLEM AREA, GETTING FILE EXTENSION
$ext=strchr($imagename,".");
$generate_name = rand(100,99999);
$generate_name_extra = rand(200,9999);
$filenamex = "PHOTO_".$generate_name.$generate_name_extra."_".time();
$filenamex_thumb = $filenamex."_thumb";
// COMPLETE FILENAME WITH EXTENSION
$filename = $filenamex.strtolower($ext);
$handle = new upload($file);
if ($handle->uploaded) {
///// 1 ////////////////////////////////////////////////////////////////////
$handle->file_new_name_body = $filenamex_thumb;
$handle->image_resize = true;
$handle->image_x = '300';
$handle->image_ratio_y = true;
$handle->jpeg_quality = '100';
// ABSOLUTE PATH BELOW
$handle->process($absoRoot.'covers/thumbs/');
if ($handle->processed) {
// SUCCESSFUL RESPONSE
}
else
{
// FAILED RESPONSE
}
}
}
网络形式是:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="fileupload[]" id="fileupload" type="file" multiple>
我真的非常需要文件扩展名来正确地在线提供文件,但我找不到在哪里找到它。我尝试在上面指定的问题区域中使用$files[$i][$k]
代替$imagename
,以及$file
和其他可能的解决方案,但我无法发现哪一个会给我带扩展名的文件名。
希望有人能指出来。感谢您的时间和帮助!
答案 0 :(得分:1)
$ext=array_pop(explode('.', $imagename));
答案 1 :(得分:0)
您正在寻找的功能是pathinfo()。
$pathdata = pathinfo($filename);
$extension = $pathdata['extension'];