2013-02-20 89 views
0

我上傳圖片的名稱爲#included,但圖片無法顯示。在php中的圖片上傳問題

例如,如果我創建了一個文件名5677PlayadelRey,#4_LR.jpg Joomla的文件系統無法加載它,但如果我名字5677PlayadelRey,Unit4_LR. jpg它工作正常。

感謝您的提前。

+0

你是什麼意思「Joomla的文件系統無法加載它」?什麼是Joomla試圖處理圖像,這需要加載圖像?如果我可以使用## – Oswald 2013-02-20 04:56:01

回答

1

這是因爲#字符指定頁面上的散列/ ID。這是在網址中使用的非法字符。

逗號,也是東西,不應該是URL

+0

。我可以使用#或不使用圖像名稱嗎?我的客戶希望使用圖像名稱# – 2013-02-20 04:53:33

+0

@AbhishekPandey查看我的答案。 http://stackoverflow.com/a/14972529/1270996 – 2013-02-20 04:55:37

1

中您可以使用urlencode,以確保您的文件名是針對URL安全。

http://php.net/manual/en/function.urlencode.php

只有當你需要使用的文件名的URL,您可以使用此功能。你可以保留你想要的文件名。

0

#沒有在URL傳遞,因此使用任何與#

0

替換如果您正在使用Joomla與

<?php 
    // define a constant for the maximum upload size 
    define ('MAX_FILE_SIZE', 1024 * 50); 

    if (array_key_exists('upload', $_POST)) { 
     // define constant for upload folder 
     define('UPLOAD_DIR', '/path/to/images/'); 
     // replace any spaces in original filename with underscores 
     $file = str_replace('#', '_', $_FILES['image']['name']); 
     // create an array of permitted MIME types 
     $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 
    'image/png'); 

     // upload if file is OK 
     if (in_array($_FILES['image']['type'], $permitted) 
      && $_FILES['image']['size'] > 0 
      && $_FILES['image']['size'] <= MAX_FILE_SIZE) { 
     switch($_FILES['image']['error']) { 
      case 0: 
      // check if a file of the same name has been uploaded 
      if (!file_exists(UPLOAD_DIR . $file)) { 
       // move the file to the upload folder and rename it 
       $success = 
    move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR . 
    $file); 
      } else { 
       $result = 'A file of the same name already exists.'; 
      } 
      if ($success) { 
       $result = "$file uploaded successfully."; 
      } else { 
       $result = "Error uploading $file. Please try again."; 
      } 
      break; 
      case 3: 
      case 6: 
      case 7: 
      case 8: 
      $result = "Error uploading $file. Please try again."; 
      break; 
      case 4: 
      $result = "You didn't select a file to be uploaded."; 
     } 
     } else { 
     $result = "$file is either too big or not an image."; 
     } 
    } 
    ?> 
0

試試這個,要求所有文件名是字母數字+下劃線。你安裝的許多插件可能會基於這個假設。否則事情可能會破裂。

0

在你的方法是處理圖像:

jimport('joomla.filesystem.file'); 
$input = JFactory::getApplication()->input; 

然後,用

$your_photo_name = JFile::makeSafe($input->get('your_photo_name'); 

這將使得文件名是安全通過的Joomla使用!系統