0

Consider I have an image named "car.jpg".

I have multi-language stores in my site and client wants to show the same image in various languages. Like car is called voiture in French so the image name should be "voiture.jpg", but it will show the same image i.e. car.jpg.

Also while saving / downloading the image it should get saved as voiture.jpg from the French store and car.jpg from the English store.

I have plans to input the names of the images from the client via a back-end panel, but can’t get ideas about how to implement this in front-end.

Note:- The image is not on my server

I have copied the image on fly and can use it as below, using class upload, but need a better option than coping image as there are above 4000 images.

<img src='./media/scene7/car.jpg' alt='car'>

<?php
    include('class.upload.php');

    $img = new Upload('media/scene7/car.jpg');

    if ($img->uploaded) {
        $img->file_new_name_body = 'voiture';
        $img->file_auto_rename = false;
        $img->file_overwrite = true;
        $img->Process('./media/scene7/translated/');
    }else{
    }

    echo "<br /><br />Car is called voiture in French, you are seeing the image of voiture.<br />";
?>
    <img src='./media/scene7/translated/voiture.jpg' alt='car'>

<?php

    if ($img->uploaded) {
        $img->file_new_name_body = 'auto';
        $img->file_auto_rename = false;
        $img->file_overwrite = true;
        $img->Process('./media/scene7/translated/');
    }else{
        echo "not uploaded";
    }

    echo "<br /><br />Car is called auto in German, you are seeing the image of auto.<br />";

?>
    <img src='./media/scene7/translated/auto.jpg' alt='car'>

<?php

    if ($img->uploaded) {
        $img->file_new_name_body = 'coche';
        $img->file_auto_rename = false;
        $img->file_overwrite = true;
        $img->Process('./media/scene7/translated/');
    }else{
        echo "not uploaded";
    }

    echo "<br /><br />Car is called coche in Spanish, you are seeing the image of coche.<br />";

?>
    <img src='./media/scene7/translated/coche.jpg' alt='car'>

<?php
    $img = new Upload('http://s7d7.scene7.com/is/image/zeon/Stack_Mouse');

    if ($img->uploaded) {
        echo 'uploaded image from url';
    }else{
        echo $img->error;
    }
?>
Deepika Janiyani
  • 1,487
  • 9
  • 17
  • you want the `image src` to print `voiture.jpg`? but use the `car.jpg` as the image? or have both `voiture.jpg` and `car.jpg` images and use the image required? im confused. – Jo E. Dec 13 '13 at 06:23
  • copy car.jpg to voiture.jpg somewhere and give voiture link to user? – Nikhil Kudtarkar Dec 13 '13 at 06:25
  • @Deadpool I want to have only one image, i.e. car.jpg but while showing it on French store, it should show voiture.jpg – Deepika Janiyani Dec 13 '13 at 06:33

4 Answers4

2

you can have images as blobs in your database and give names as you like it.

pros and cons for storing images as blobs can be find out from the below link php:Store image into Mysql blob, Good or bad?

Community
  • 1
  • 1
1

Have a database table that lists all the image filenames that you want to display to the user, along with their real URLs. For example, the table might have

+-------------+--------------------------+
|FILENAME     |URL                       |         
+-------------+--------------------------+
|car.jpg      |./media/scene7/car.jpg    |
|voiture.jpg  |./media/scene7/car.jpg    |
|auto.jpg     |./media/scene7/car.jpg    |
|truck.jpg    |./media/scene7/truck.jpg  |
|camion.jpg   |./media/scene7/truck.jpg  |
|lastwagen.jpg|./media/scene7/truck.jpg  |
+-------------+--------------------------+

Now write a page image.php, which expects a filename as a query parameter. It should take the query parameter and look it up in the database table, then do a redirect to the URL that it finds.

You can then include your image in the page as something like

<img src="image.php?file=voiture.jpg" alt="voiture.jpg"/>

When the browser requests this image, your page will be called, and the image will end up coming from .media/scene7/car.jpg.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
0

You can make a hash table like 'car' => 'car.jpg' and 'voiture' => 'car.jpg'. when every time the clients visits voiture.jpg you can return car.jpg.

Seeinyou
  • 70
  • 3
0

You can achive this by implemetlnting one cofig file for each language. Here is explanation:-

Suppose you have some images like user.jpg, profile.jpg etc. Now create one french.php file.

Structure of french.php file:-

<?php
$lang=array();
$lang['user']='french_transalation_of_user';
$lang['profile']='french_transalation_of_profile';
?>

In same way add all your image names which you want to display in french. Now call these names dynamically in webpage. You can also create as many as language.php as you want.

I hope you understand the logic. Sorry for bad english.

Bit_hunter
  • 789
  • 2
  • 8
  • 25