- Timestamp:
- Nov 7, 2008, 9:33:03 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/examples/www/img2txt.php
r3310 r3312 26 26 27 27 $argv = array(basename($img2txt_php)); 28 $args = ''; 28 $file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL; 29 $filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL; 30 $args = NULL; 29 31 if(isset($_REQUEST['args'])) 30 32 { 31 33 $args = $_REQUEST['args']; 32 } 33 $args=trim($args); 34 if(strlen($args)) 35 { 36 foreach(explode(' ', $args) as $arg) 37 { 38 $argv[] = $arg; 34 if(strlen($args)) 35 { 36 foreach(explode(' ', $args) as $arg) 37 { 38 $argv[] = $arg; 39 } 39 40 } 40 41 } … … 224 225 $stderr .= sprintf("Usage: %s [OPTIONS]... <IMAGE>\n", $argv[0]); 225 226 $stderr .= sprintf("Convert IMAGE to any text based available format.\n"); 226 $stderr .= sprintf("Example : %s -w 80 -f ansi ./caca.png\n\n", $argv[0]);227 $stderr .= sprintf("Example : -W 80 -f html logo-caca.png\n\n", $argv[0]); 227 228 $stderr .= sprintf("Options:\n"); 228 229 $stderr .= sprintf(" -h, --help\t\t\tThis help\n"); … … 348 349 } 349 350 351 global $file, $filename; 352 353 if((! $file) && ($argc == 2) && ($argv[1] == 'logo-caca.png')) 354 { 355 $file = 'logo-caca.png'; 356 $argc = 1; 357 } 358 350 359 if($argc > 1) 351 360 { … … 354 363 return 1; 355 364 } 356 357 $file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;358 $filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;359 365 360 366 if(! $file) … … 466 472 return 0; 467 473 } 468 if(main() || strlen($stdout) || strlen($stderr)) 474 $ret = 1; 475 if(isset($_REQUEST['args']) || $file) 476 { 477 $ret = main(); 478 } 479 if($ret || strlen($stdout) || strlen($stderr)) 469 480 { 470 481 header('Content-Type: text/html; charset=UTF-8'); … … 484 495 <br /> 485 496 <label for="args">Options:</label> 486 <input id="args" name="args" type="text" value="<?= htmlspecialchars($args)?>" size="80" />497 <input id="args" name="args" type="text" value="<?= isset($_REQUEST['args']) ? htmlspecialchars($_REQUEST['args']) : '' ?>" size="80" /> 487 498 <br /> 488 499 <input type="submit" /> … … 492 503 if(strlen($stderr)) 493 504 { 494 ?><pre xml:space="preserve"><em><?= htmlspecialchars($stderr) ?></em></pre><?php505 ?><pre xml:space="preserve"><em><?= preg_replace('!(logo-caca[.]png)!', '<a href="$1">$1</a>', htmlspecialchars($stderr)) ?></em></pre><?php 495 506 ; 496 507 } 497 508 if(strlen($stdout)) 498 509 { 499 ?><pre xml:space="preserve"><?= htmlspecialchars($stdout) ?></pre><?php510 ?><pre xml:space="preserve"><?= preg_replace('!([&]lt;)([.a-zA-Z0-9]+[@][-.a-zA-Z0-9]+)([&]gt;)!', '$1<a href="mailto:$2">$2</a>$3', preg_replace('!(\s|^)(http://[-.:_/0-9a-zA-Z%?=&;#]+)(\s|$)!', '$1<a href="$2">$2</a>$3', htmlspecialchars($stdout))) ?></pre><?php 500 511 ; 501 512 }
Note: See TracChangeset
for help on using the changeset viewer.