php中的图像上传问题

php中的图像上传问题,php,joomla,image-upload,Php,Joomla,Image Upload,我正在上传包含#名称的图像,但图像未显示 例如,如果我创建了一个文件名5677PlayadelRey,#4_LR.jpgJoomla的文件系统无法加载它,但是如果我命名为5677PlayadelRey,Unit4_LR。jpg它工作得很好 感谢提前通知。这是因为#字符在页面上指定了一个哈希/ID。它是在url中使用的非法字符 逗号,也不应该在url中您可以使用urlencode来确保您的文件名对于url是安全的 仅当需要在URL中使用文件名时,才能使用此选项。你可以保留你想要的任何文件名 #未

我正在上传包含
#名称的图像,但图像未显示

例如,如果我创建了一个文件名
5677PlayadelRey,#4_LR.jpg
Joomla的文件系统无法加载它,但是如果我命名为
5677PlayadelRey,Unit4_LR。jpg
它工作得很好

感谢提前通知。

这是因为
#
字符在页面上指定了一个哈希/ID。它是在url中使用的非法字符


逗号
也不应该在url中

您可以使用
urlencode
来确保您的文件名对于url是安全的

仅当需要在URL中使用文件名时,才能使用此选项。你可以保留你想要的任何文件名

#
未在URL中传递,因此请使用任何替换为
#

的内容

<?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.";
      }
    }
    ?>

如果您使用的是Joomla,则要求所有文件名都是字母数字+下划线。您安装的许多插件可能都基于此假设。否则事情可能会破裂。

在处理图像的方法中:

jimport('joomla.filesystem.file');
$input = JFactory::getApplication()->input;
然后,使用

$your_photo_name = JFile::makeSafe($input->get('your_photo_name');
这将使文件名被Joomla安全使用!系统

如果我能使用#。我是否可以将图像名称与#一起使用?我的客户想将映像名与“Joomla的文件系统无法加载”一起使用,这是什么意思?Joomla试图对需要加载图像的图像做什么?