Debian Codegraph @

caca-php/examples/www/import.php

raw
1 <?php
2 header('Content-Type: text/html; charset=UTF-8');
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <?php
9 /*
10 * import libcaca importers test program
11 * Copyright (c) 2008 Benjamin C. Wiley Sittler <[email protected]>
12 *
13 * This file is a Php port of "examples/import.c"
14 * which is:
15 * Copyright (c) 2006 Jean-Yves Lamoureux <[email protected]>
16 * All Rights Reserved
17 *
18 * This program is free software. It comes without any warranty, to
19 * the extent permitted by applicable law. You can redistribute it
20 * and/or modify it under the terms of the Do What the Fuck You Want
21 * to Public License, Version 2, as published by Sam Hocevar. See
22 * http://www.wtfpl.net/ for more details.
23 */
24
25 $imports = caca_get_import_list();
26
27 $file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
28 $filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
29 $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
30
31 ?>
32 <head>
33 <title><?= ($filename == NULL) ? '' : htmlspecialchars($filename . ' | ') ?>libcaca importers test program</title>
34 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
35 </head>
36 <body>
37 <?php
38
39 if ($file == NULL)
40 {
41 ?>
42 <form id="importform" name="importform" action="#" enctype="multipart/form-data" method="post">
43 <label for="file">File:</label>
44 <input id="file" name="file" type="file" />
45 <br />
46 <input type="submit" value="Import" />
47 <label for="format">as</label>
48 <select name="format" id="format" onchange="update_preview(this);">
49 <?php
50 foreach($imports as $import_format => $name)
51 {
52 ?><option value="<?= htmlspecialchars($import_format) ?>"<?=
53 ($format == $import_format) ? ' selected="selected"' : '' ?>><?=
54 htmlspecialchars($name . " (" . $import_format . ")") ?></option><?php
55 }
56 ?>
57 </select>
58 </form>
59 <?php
60 ;
61 }
62
63 if($file)
64 {
65 $cv = caca_create_canvas(0, 0);
66 if(! $cv)
67 {
68 die("Can't create canvas\n");
69 }
70
71 if(caca_import_file($cv, $file, ($format == NULL) ? "" : $format) < 0)
72 {
73 die("could not import `" . htmlspecialchars($filename) . "'.\n");
74 }
75
76 echo caca_export_string($cv, "html3");
77 }
78 else
79 {
80 ?>See the <a href="export.php">libcaca export test program</a> for an <a
81 href="export.php?format=caca">example file</a>.<?php
82 }
83
84 ?>
85 </body>
86 </html>