1

Well,

In my database table, I have set the image name as D@üäö#-09710.jpg. When I call the table data all data is showing except this image is not showing because of this name!!!

I have checked by inspecting the element and it's showing me:

src="images/users/D@üäö#-09710.jpg"

Even the image is successfully uploaded with this name:

D@üäö#-09710.jpg

But when I directly view the image using this image URL then the browser showing me:

The requested URL /xxx/xxxx/images/users/D@üäö was not found on this server.

Another strange thing is that when I copy the URL from the browser and paste it here then it looks like this:

http://localhost/xxx/xxxx/images/users/D@%C3%BC%C3%A4%C3%B6#.jpg

So it seems like special characters is not reading properly!

PHP page header is like that:

<?php require_once('admin/init.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">    
    <meta name="description" content="">
    <meta name="keywords" content="">    
    <title>ccrroipr</title>    
    <?php require_once('includes/css.php'); ?>
</head>
<body>

PHP connection:

try {
    $this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/database'), Config::get('mysql/username'), Config::get('mysql/password'), array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"));
    $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $e) {
    die($e->getMessage());
}

And the Database Collation is:

utf8mb4_unicode_ci

Shibbir
  • 409
  • 3
  • 14

1 Answers1

2

URLs can't contain all of those characters, see Characters allowed in a URL for more info. You have to use urlencode() to transform the URL from D@üäö#-09710.jpg to D%40%C3%BC%C3%A4%C3%B6%23-09710.jpg. You can keep the filename and database entry as-is (assuming your filesystem can handle the characters), but use urlencode when creating the link.

onik
  • 1,922
  • 1
  • 18
  • 32