Changeset 3269 for libcaca/trunk


Ignore:
Timestamp:
Nov 4, 2008, 5:13:13 AM (11 years ago)
Author:
bsittler
Message:

works well enough to import the files exported by export.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/www/import.php

    • Property svn:executable deleted
    r3266 r3269  
    1 #!/usr/bin/php5
     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">
    28<?php
    39/*
     
    2127$imports = caca_get_import_list();
    2228
    23 if($argc < 2 || $argc > 3)
     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)
    2442{
    25         $msg = ($argv[0] . ": wrong argument count\n" .
    26                         "usage: " . $argv[0] . " file [<format>]\n" .
    27                         "where <format> is one of:\n");
    28         foreach($imports as $format => $name)
    29                 $msg .= " \"" . $name . "\" (" . $format . ")\n";
    30         die($msg);
     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      ;
    3163}
    3264
    33 $cv = caca_create_canvas(0, 0);
    34 if(! $cv)
     65if($file)
    3566{
    36         die("Can't create canvas\n");
     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");
    3779}
    3880
    39 if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0)
    40 {
    41         die($argv[0] . ": could not open `" . $argv[1] . "'.\n");
    42 }
    43 
    44 $dp = caca_create_display($cv);
    45 if(! $dp)
    46 {
    47         die("Can't create display\n");
    48 }
    49 
    50 caca_refresh_display($dp);
    51 
    52 caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
    53 
    5481?>
     82</body>
     83</html>
Note: See TracChangeset for help on using the changeset viewer.