D
D
Dmitry2017-11-22 19:23:43
PHP
Dmitry, 2017-11-22 19:23:43

How to print image to csv using php?

Hello, I made a script that prints in php and makes it in csv format.
So I'm wondering how to implement loading images in csv via php.
Option - insert html tag failed :(
Here is my code:

// output headers so that the file is downloaded rather than displayed

$filename = "basket_" . date('Y-m-d') . ".csv";
header('Content-Type: text/csv; charset=utf-8');
header("Content-Disposition: attachment; filename=\"$filename\"");

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array(' ID модели ', ' Имя модели ', ' Фамилия модели ', ' День рождения ', ' Месяц рождения ', ' Год рождения ', ' Рост ', ' Мобильный телефон ', ' Контактное лицо ',  ' Профиль модели(Фото и подробная инфо.) '));

// fetch the data
mysql_connect('localhost', 'root', 'pass');
mysql_select_db('db');
$rows = mysql_query("SELECT user.id, user.name, user.surname, user.day, user.month, user.year, user.height, user.phone_mob, user.contact, basket.user
            FROM user
            INNER JOIN basket
            ON user.id = basket.user
            ORDER BY basket.id;");

// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows))
{
    if (isset($row['user']))
    {
        $row['user'] = 'http://only-stars.ru/models?id='.$row['user'];
    }
    if ($row['name'] == '')
    {
        $row['name'] = "(не указано)";
    }
    if ($row['surname']== '')
    {
        $row['surname'] = "(не указано)";
    }
    if ($row['day'] == '')
    {
        $row['day'] = "(не указано)";
    }
    if ($row['month'] == '')
    {
        $row['month'] = "(не указано)";
    }
    if ($row['year'] == '')
    {
        $row['year'] = "(не указано)";
    }
    if ($row['height'] == '')
    {
        $row['height'] = "(не указано)";
    }
    if ($row['phone_mob'] == '')
    {
        $row['phone_mob'] = "(не указано)";
    }
    if ($row['contact'] == '')
    {
        $row['contact'] = "(не указано)";
    }
    fputcsv($output, $row);
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zoozag, 2017-11-22
@maxdit

CSV (from the English Comma-Separated Values ​​- comma-separated values) is a text format designed to represent tabular data.

A
Alexander Aksentiev, 2017-11-22
@Sanasol

csv is not excel

K
krypt3r, 2017-11-23
@krypt3r

What for? Save in CSV, for example, a URL or a local path to an image.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question