ImageCMS Templates 4.10-4.12.1
Latest templates from ImageCMS 4.12, authorization is required to download.
An example of creating a CSV with a line separator ";"
The code:
// 1
$fp = fopen('./fileName.csv', 'w');
if ($fp === false) {
// 2
exit('Can not create file (No Rights) ./fileName.csv');
}
// 3
$models = [
[
'name' => 'Visa',
'type' => 'Card',
'balance' => '10.0'
],
[
'name' => 'Master',
'type' => 'Card',
'balance' => '0'
]
];
// 4
fwrite($fp, '"Имя";"Тип";"Баланс"' . "\n");
foreach ($models as $v) {
fwrite($fp, '"' . $v['name'] . '";"'
. $v['type'] . '";"'
. $v['balance'] . '"'
. "\n");
}
// 5
fseek($fp, 0);
fclose($fp);
// 6
$data = file_get_contents('./fileName.csv');
// 7
header('Content-Type: text/csv'); // 7.1
header('Content-Disposition: attachment; filename="fileName.csv"'); // 7.2
header("Content-Transfer-Encoding: binary"); // 7.3
header('Expires: 0'); // 7.4
header('Pragma: no-cache'); // 7.5
header("Content-Length: ".strlen($data)); // 7.6
// 8
exit($data);
Note :
For the header to fire, there must be no BOM and no output of information before the code fires.
1 - Create a file fileName.csv in the root of the site for writing.
2 - We warn about an error if there are no rights to write.
3 - An array of values that we will process
4 - Writing to a file. '"Name ";" Type";"Balance"' . "\n" (";" - line separator, "\n" - line break).
5 - Return the pointer to the beginning of the file and close the file (save).
6 - Read the file again.
7 - We give headers for the ability to download the file.
7.1 - Parameter defining file type.
7.2 - Pointer to file attachment.
7.3 - In what form to transfer (in this case, in binary).
7.4, 7.5 - Pointer not to cache the file and constantly give the current one.
7.6 - The size of the content part of the file.
8 - We display information that, in conjunction with the headers, will make it possible to download it to a CSV file.
Result:
Latest templates from ImageCMS 4.12, authorization is required to download.
Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.
Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.
When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.
After developing any tool in PHP, the question becomes how resourceful the created code is and what elements it still affects. Let's take a look at xhprof installation, configuration, and how to work with xhprof.
Let's analyze the possibility of combining conditions in a query by groups in Propel. Consider an example of filtering by fields using ->condition() and ->combine().
Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .
The purpose of the article was to join (join) a table not declared in the schema (schema.xml) in propel2. Apparently a rare case or simply not enough documentation for this Propel ORM.