2011-03-10 39 views

回答

4

http://codeigniter.com/user_guide/libraries/file_uploading.html

$this->upload->data() 

這是一個輔助函數返回一個包含所有涉及到你上傳的文件中的數據的數組。這裏是數組原型:用戶上傳的東西

所以經過
Array 
(
    [file_name] => mypic.jpg 
    [file_type] => image/jpeg 
    [file_path] => /path/to/your/upload/ 
    [full_path] => /path/to/your/upload/jpg.jpg 
    [raw_name]  => mypic 
    [orig_name] => mypic.jpg 
    [client_name] => mypic.jpg 
    [file_ext]  => .jpg 
    [file_size] => 22.2 
    [is_image]  => 1 
    [image_width] => 800 
    [image_height] => 600 
    [image_type] => jpeg 
    [image_size_str] => width="800" height="200" 
) 

,你可能想在你的數據庫文件的擴展名與有關圖像的其他詳細信息存儲:-)

3
$name_of_file_with_extn = $this->upload->data('file_name') 

你可將商品的名字從名單如下改變

file_name Name of the file that was uploaded, including the filename extension file_type File MIME type identifier file_path Absolute server path to the file full_path Absolute server path, including the file name raw_name File name, without the extension orig_name Original file name. This is only useful if you use the encrypted name option. client_name File name as supplied by the client user agent, prior to any file name preparation or incrementing file_ext Filename extension, period included file_size File size in kilobytes is_image Whether the file is an image or not. 1 = image. 0 = not. image_width Image width image_height Image height image_type Image type (usually the file name extension without the period) image_size_str A string containing the width and height (useful to put into an image tag)

這可以幫助你。

$saved_file_name = $this->upload->data('file_name'); 
// will give you the filename along with the extension 

如果你想在上傳之前只得到文件的擴展名,使用PHP核心:

$file_ext = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION); 

0

你上傳的文件後,你可以得到它的屬性讓它乾淨

$filename= $_FILES["file"]["name"]; 
$file_ext = pathinfo($filename,PATHINFO_EXTENSION);