我遇到了一个问题,在 /uploads 中出现名称为 69398f524b17741a34ee3f77234797e2.jpg 等的文件。似乎该文件被编码为随机 MD5。
在库 Upload.php 中,我发现 MD5 用于添加一个数字来结束文件名,如果它发现具有相同名称的文件已经存在。
在模型中我有这样的代码:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1000';
$config['max_width'] = '2024';
$config['max_height'] = '2024';
$config['encrypt_name'] = TRUE;
//var_dump($config);
$this->load->library('upload', $config);
$temp_files = $_FILES;
// var_dump($temp_files);
// echo "files";
// var_dump($_FILES);
$count = count ($_FILES['userfile']['name']);
for ($i=0; $i<=$count-1; $i++){
$_FILES['file'] = array (
'name'=>$temp_files['userfile']['name'][$i],
'type'=>$temp_files['userfile']['type'][$i],
'tmp_name'=>$temp_files['userfile']['tmp_name'][$i],
'error'=>$temp_files['userfile']['error'][$i],
'size'=>$temp_files['userfile']['size'][$i]);
unset($_FILES['userfile']);
var_dump($_FILES);
if ( ! $this->upload->do_upload('file'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('insert', $error);
}
else
{
$this->upload->do_upload('file');
$tmp_data = $this->upload->data();
echo "<hr>";
var_dump($tmp_data);
}//end else
}//end for
}//end do_upload
var_dump($_FILES) 返回
array (size=1)
'file' =>
array (size=5)
'name' => string 'Desert.jpg' (length=10)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string 'C:\Windows\Temp\php3776.tmp' (length=27)
'error' => int 0
'size' => int 845941
var_dump($tmp_data) 返回
array (size=14)
'file_name' => string '69398f524b17741a34ee3f77234797e2.jpg' (length=36)
'file_type' => string 'image/jpeg' (length=10)
'file_path' => string 'D:/server/www/melok/uploads/' (length=28)
'full_path' => string 'D:/server/www/melok/uploads /69398f524b17741a34ee3f77234797e2.jpg' (length=64)
'raw_name' => string '69398f524b17741a34ee3f77234797e2' (length=32)
'orig_name' => string 'Desert.jpg' (length=10)
'client_name' => string 'Desert.jpg' (length=10)
'file_ext' => string '.jpg' (length=4)
'file_size' => float 826.11
'is_image' => boolean true
'image_width' => int 1024
'image_height' => int 768
'image_type' => string 'jpeg' (length=4)
'image_size_str' => string 'width="1024" height="768"' (length=25)