D
D
Dmitry2016-02-19 10:40:19
PHP
Dmitry, 2016-02-19 10:40:19

How to save images from xlsx with original titles?

There is an xlsx file in the cells of which there are pictures. The cell contains the name and path to the original image like "../FirstDir/SecondDir/foto/51058.jpg". After unpacking the xlsx file, I found that the images have names like "image1.jpeg". How to save pictures from a document by giving them the names they originally had?
I get pictures like this:

$zip = zip_open($inputFileName);
if ($zip) {
    while ($zip_entry = zip_read($zip)) {
        $zipentry = zip_entry_name($zip_entry);
        $pi = pathinfo($zipentry);
        if ($pi['extension'] == 'jpeg') {
            $imagePath = $uploaddir . 'images/';
            $path = $imagePath . $pi['filename'] . '.' . $pi['extension'];
            if ($fd = @fopen($path, "w+")) {
                fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
                fclose($fd);
            }
            else {
                echo "Failed to open $path<br/>";
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
V Sh., 2016-02-19
@JuniorNoobie

If, when opening an Excel file, you see the original inscription (pointing at the picture or something else), then it is logical to assume that somewhere this address is still stored in the .xlsx xml files. As far as I remember, starting with MS Excel2010, everything is beautifully structured into folders if you view the .xlsx file. I did not work with drawings, but I worked with graphs. So, all the information on the charts was in the charts folder and contained a bunch of xml - one for each chart. Maybe something like that happens with drawings. I mean that there is a source data (image1) and a description for it in the form of xml.

A
Andrey Evdokimov, 2016-05-01
@Uncle_Stranger

I heard somewhere that you can almost rename it to zip and they will be unzipped from there. Well, at least what to ask in Yandex - prompted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question