source: libcaca/trunk/caca-php/examples/www/import.php @ 3271

Last change on this file since 3271 was 3271, checked in by bsittler, 11 years ago

clearer wording.

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1<?php
2header('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 <bsittler@gmail.com>
12 *
13 *  This file is a Php port of "examples/import.c"
14 *  which is:
15 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
16 *                All Rights Reserved
17 *
18 *  $Id: import.php 3271 2008-11-04 04:45:23Z bsittler $
19 *
20 *  This program is free software. It comes without any warranty, to
21 *  the extent permitted by applicable law. You can redistribute it
22 *  and/or modify it under the terms of the Do What The Fuck You Want
23 *  To Public License, Version 2, as published by Sam Hocevar. See
24 *  http://sam.zoy.org/wtfpl/COPYING for more details.
25 */
26
27$imports = caca_get_import_list();
28
29$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
30$filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
31$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
32
33?>
34<head>
35<title><?= ($filename == NULL) ? '' : htmlspecialchars($filename . ' | ') ?>libcaca importers test program</title>
36<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
37</head>
38<body>
39<?php
40
41if ($file == NULL)
42{
43    ?>
44<form id="importform" name="importform" action="#" enctype="multipart/form-data" method="post">
45<label for="file">File:</label>
46<input id="file" name="file" type="file" />
47<br />
48<input type="submit" value="Import" />
49<label for="format">as</label>
50<select name="format" id="format" onchange="update_preview(this);">
51<?php
52        foreach($imports as $import_format => $name)
53        {
54                ?><option value="<?= htmlspecialchars($import_format) ?>"<?=
55                        ($format == $import_format) ? ' selected="selected"' : '' ?>><?=
56                        htmlspecialchars($name . " (" . $import_format . ")") ?></option><?php
57        }
58?>
59</select>
60</form>
61<?php
62      ;
63}
64
65if($file)
66{
67        $cv = caca_create_canvas(0, 0);
68        if(! $cv)
69        {
70                die("Can't create canvas\n");
71        }
72       
73        if(caca_import_file($cv, $file, ($format == NULL) ? "" : $format) < 0)
74        {
75                die("could not import `" . htmlspecialchars($filename) . "'.\n");
76        }
77       
78        echo caca_export_string($cv, "html3");
79}
80else
81{
82        ?>See the <a href="export.php">libcaca export test program</a> for an <a
83href="export.php?format=caca">example file</a>.<?php
84}
85
86?>
87</body>
88</html>
Note: See TracBrowser for help on using the repository browser.