text
stringlengths 1
254
| output
stringlengths 2
255
|
|---|---|
The best way is to stick a ?php phpinfo();? part on a page and load it up.
|
æãç°¡åãªã®ã¯ASPã¿ã°ãäœ¿ãæ¹æ³ã§ããããããã°ASPã®æ§ã« %ãš% ãã³ãŒãåºåããšããŠäœ¿çšããããšãåºæ¥ãŸããæåãªHTMLãšã㣠ã¿ã¯(ä»ã®ãšãã)ASPã¿ã°ãè³¢ãæ±ã£ãŠãããŸããASPã¹ã¿ã€ã«ã®ã¿ã°ã æå¹ã«ããã«ã¯ php.ini ãã¡ã€ã«ã§ asp_tags ãèšå®ããããApacheãã£ã¬ ã¯ãã£ãã䜿çšããŸãã
|
This list can 't really be documented in the PHP documentation because it will change from one server to another.
|
11. ãããããèšå®ãããŠãã倿°ãå
šãŠç¶²çŸ
ãããªã¹ãã¯ã©ãã«ããã®ã§ ããïŒãªãPHPã®ããã¥ã¡ã³ãã«ã¯ãã®äžèЧããªãã®ã§ããïŒ
|
I' m trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can't seem to find it.
|
äžçªè¯ãæ¹æ³ã¯HTMLã« ?php phpinfo();? ãšæžããŠãã®ããŒãžãããŒãããããšã§ããããã«ã¯ç°å¢å€æ°ããŠã§ã ãµãŒããèšå®ããç¹æ®ãªå€æ°ã®äžèЧãå«ããPHPã®èšå®ã«é¢ããããã ãæ
å ±ã衚瀺ãããŸãããããããªã¹ããPHPã®ããã¥ã¡ã³ãã«ç¡ãã® ã¯ãåã
ã®ãµãŒãã«ãããã®é
ç®ãšå
容ãç°ãªãããã§ãã
|
Environment variables are normal global variables, so you must either declare them as global variables in your function (by using "global $DOCUMENT_ROOT;", for example) or by using the global variable array (ie, "$GLOBALS["DOCUMENT_ROOT"]").
|
12. ãŠãŒã¶å®çŸ©é¢æ°ã®äžã§ãæšæºçãª($DOCUMENT_ROOTã$HTTP_REFERERçã®) CGI倿°ã«ã¢ã¯ã»ã¹ãããã®ã§ãããPHPã¯ãããã®å€æ°ãèŠã€ããããš ãã§ããŠããªãããã§ããäœãããããã®ã§ããïŒ
|
For example, you can now use $_SERVER[ "DOCUMENT_ROOT"] instead of $DOCUMENT_ROOT.
|
ç°å¢å€æ°ã¯éåžžã®ã°ããŒãã«å€æ°ãšåãæ§ã«æ±ãããã®ã§ã(äŸãã° global $DOCUMENT_ROOT; ã®ããã«)ãŠãŒã¶å®çŸ©é¢æ° ã®äžã§ã°ããŒãã«å€æ°ãšããŠå®£èšããããã°ããŒãã«å€æ°ã®é
åã䜿㣠ãŠ(ã€ãŸãã $GLOBALS["DOCUMENT_ROOT"] ãšããŠ)㢠ã¯ã»ã¹ããŠãã ããã
|
As the name implies, this SAPI type main focus is on developing shell (or desktop as well) applications with PHP.
|
4.3以éã§ PHP 㯠Command Line Interface ãæå³ãã CLI ãšããååã®æ°ãã SAPI å (Server Application Programming Interface)ããµããŒãããŸãã ååããåããããã«ããã® SAPI åã¯ã PHP ã«ããã·ã§ã«(ãŸãã¯ãã¹ã¯ããã)ã¢ããªã±ãŒã·ã§ ã³ã®éçºãäž»ãªå¯Ÿè±¡ãšããŠããŸãã CLI SAPI ãšä»ã® SAPI ã®éã«ã¯ã ããã€ãã®éãããããŸããæ¬ç« ã§ã¯ããããã«ã€ããŠè©³çްã説æããŸãã
|
The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental and had to be explicitly enabled with --enable-cli when running. / configure.
|
CLI SAPI ã¯ãåœå PHP 4.2.0 ã§ãª ãªãŒã¹ãããŸãããããã®æç¹ã§ã¯å®éšçãªã¹ããŒã¿ã¹ã«ãã£ãããã ./configure ãå®è¡ããéã«ãæç€ºçã« --enable-cli ãæå®ããããšã«ãããæå¹ãšããå¿
èŠ ããããŸããã PHP 4.3.0 以éã CLI SAPI ã¯ãã¯ãå®éšçãªã¹ããŒã¿ã¹ã§ã¯ãªããªã㟠ããããã®ããã åžžã« æ§ç¯ããã php (Windowsã§ã¯ php.exe ãš ããååãšãªããŸã)ãã€ããªãšããŠã€ã³ã¹ããŒã«ãããŸãã
|
You may use --disable-cli to disable it.
|
CLI SAPI ãä»ã® SAPI ãšæ¯ã¹ãæ ã®å€§ããªéãã以äžã«ç€ºããŸãã
|
By default when executing make, both the CGI and CLI are built and placed as sapi / cgi / php and sapi / cli / php respectively, in your php source directory.
|
CGI SAPI ãšç°ãªããããããåºåãããŸããã
|
If a module SAPI is chosen during configure, such as apxs, or the --disable-cgi option is used, the CLI is copied to {PREFIX} / bin / php during make install otherwise the CGI is placed there.
|
CGI SAPI ã¯ãHTTPãããã®åºåãæå¶ããæ©èœã æäŸããŠããŸãããçäŸ¡ãªæ©èœã¯ CLI SAPI ã§ã¯ãµ ããŒããããŠããŸããã
|
If you want to override the installation of the CGI binary, use make install-cli after make install.
|
以äžã«ç€ºãããã€ãã® php.ini ãã£ã¬ã¯ãã£ãã¯ã CLI SAPI ã«ããäžæžããããŸããããã¯ãã·ã§ã«ç°å¢ã§ã¯æå³ã ãªãããã§ãã
|
Note:
|
衚 23-1äžæžãããã php.ini ã®ãã£ã¬ã¯ãã£ã
|
The windows package distributes the CGI as php.exe and has a folder named cli with the CLI in it, so: cli / php.exe.
|
泚æ ãããã®ãã£ã¬ã¯ãã£ãã¯ãèšå®ãã¡ã€ã« php.ini ãŸãã¯ã«ã¹ã¿ã èš å®ãã¡ã€ã«(æå®ããå Žåã®ã¿)ã§ä»ã®å€ã«åæåã§ããŸããããã®å¶ éã¯ããããã®ããã©ã«ãå€ãå
šãŠã®èšå®ãã¡ã€ã«ãããŒã¹ããåŸã« é©çšãããããã§ãããããããããã®å€ã¯å®è¡æã«å€æŽããããšã å¯èœã§ãã (äžèšã®ãã£ã¬ã¯ãã£ãã®å
šãŠã«ã€ããŠãããåœãŠã¯ãŸãããã§ã¯ãã ãŸãããäŸãã°ã register_argc_argv)
|
See also the function php_sapi_name() and the constant PHP_SAPI.
|
ã·ã§ã«ç°å¢ã§ã®åäœã容æãšããããã«ã以äžã®å®æ°ãå®çŸ©ãããŠã㟠ãã
|
Unlike the CGI SAPI, no headers are written to the output.
|
衚 23-2CLIåºæã®å®æ°
|
CLI is started up in quiet mode by default, though the -q switch is kept for compatibility so that you can use older CGI scripts.
|
äžèšã®ããã«ã stderr ã®ãããªã¹ããªãŒã ãèªå ã§ãªãŒãã³ããå¿
èŠã¯ãªãã以äžã®ããã«ã¹ããªãŒã ãªãœãŒã¹ã®ä»£ãã ã«å®æ°ã䜿çšããã ãã§ããŸããŸããã
|
Plain text error messages (no HTML formatting).
|
CLI SAPI ã¯ãå®è¡ãããã¹ã¯ãªããã®ãã£ã¬ã¯ã ãªã«ã«ã¬ã³ããã£ã¬ã¯ããªãå€æŽ ããŸãã!
|
Table 23-1.
|
CGI SAPI ãšã®éãã瀺ãäŸã以äžã«ç€ºããŸãã
|
implicit_flush
|
CGI çã«ããå®è¡ããå Žåãåºåã¯ä»¥äžã®ããã«ãª ããŸãã
|
You still can use output buffering if you want to defer or manipulate standard output.
|
CLI SAPI ã䜿çšããå Žåã®åºåã¯æ¬¡ã®ããã«ãªã ãŸãã
|
Whereas applications written for the web are often executed very quickly, shell application tend to have a much longer execution time.
|
泚æ CGI SAPI ã¯ããã® CLI SAPI ã®åäœãã³ãã³ãã©ã€ã³å®è¡æã®ã¹ã€ãã -C ã«ã ããµããŒãããŠããŸãã
|
As of PHP 4.3.0, the PHP variables $argc and $argv are registered and filled in with the appropriate values when using the CLI SAPI.
|
PHP ãã€ããªã«ããæäŸãããã³ãã³ãã©ã€ã³ãªãã·ã§ ã³ã®äžèЧã¯ã -h ã¹ã€ãããæå®ã㊠PHP ãå®è¡ããããšã«ãããã€ã§ã調ã¹ãããšãã§ã ãŸãã
|
Regardless of version or register_globals setting, you can always go through either $_SERVER or $HTTP_SERVER_VARS.
|
CLI SAPI ã¯ãå®è¡ãã PHP ã³ãŒã ãååŸããããã«äžçš®é¡ã®ç°ãªãææ®µããµããŒãããŠããŸãã
|
This is a limitation because those default values are applied after all configuration files have been parsed.
|
PHP ã«ç¹å®ã®ãã¡ã€ã«ã®å®è¡ãæç€ºããã
|
To ease working in the shell environment, the following constants are defined:
|
å®è¡ãã PHP ã³ãŒããã³ãã³ãã©ã€ã³ã§çŽæ¥æå®ããã
|
Given the above, you don 't need to open e.g. a stream for stderr yourself but simply use the constant instead of the stream resource:
|
泚æ ãã®äŸãããã¿ãŠäžãããéå§/çµäºã¿ã°ããããŸãã! -r ã¹ã€ããã䜿çšããå Žåããããã®ã¿ã°ã¯äžèŠ ãšãªããŸãããããã®ã¿ã°ã䜿çšãããšããŒãµãšã©ãŒãçºçããŸãã
|
The CLI SAPI does not change the current directory to the directory of the executed script!
|
å®è¡ãã PHP ã³ãŒããæšæºå
¥å (stdin )ã§æå®ããã
|
?php / * Our simple test application named test.php* / echo getcwd(), "\n";?
|
ããã¯åŒ·åãªæ©èœã§ã以äžã®(ä»®æ³çãª)äŸã«ç€ºãããã«ãåçã« PHP ã³ãŒããçæããå®è¡ãã€ããªã«å
¥åããããš ãã§ããŸãã
|
$some_application _BAR_ some_filter _BAR_ php _BAR_ sort -u final_output.txt
|
ã¹ã¯ãªããã«æå®ããåŒæ°ãæå - ã§å§ãŸã£ãŠããªã éããç¹ã«çæãã¹ãããšã¯ãããŸãããã¹ã¯ãªããã«æå®ããåŒæ°ãæ å - ã§å§ãŸãå Žåã PHP èªäœãã ããããŒã¹ããå¿
èŠããããšã¿ãªããããåé¡ãçºçããŸãã ããã鲿¢ãããããåŒæ°ãªã¹ãã»ãã¬ãŒã¿ -- ãäœ¿çš ããŠäžããã PHP ã«ããŒã¹ãããåŒæ°ã®åŸã« ãã®ã»ãã¬ãŒã¿ã眮ããšããã®åŸã®å
šãŠã®åŒæ°ã¯ãã®ãŸãŸããŒã¹ãããã« ã¹ã¯ãªããã«æž¡ãããŸãã
|
The number of arguments which can be passed to your script is not limited by PHP (the shell has a certain size limit in the number of characters which can be passed; usually you won't hit this limit).
|
ãŸãã PHP ãã·ã§ã«ã¹ã¯ãªãããšããŠäœ¿çšããä»ã® ææ®µããããŸããæåã®è¡ã #!/usr/bin/php ã§å§ãŸãã PHP ã®éå§/çµäºã¿ã°ã®äžã«éåžžã® PHP ã³ãŒããç¶ãã¹ã¯ãªãããæžããé©åœãªãã¡ã€ã« å®è¡å±æ§ãèšå®ããããšãå¯èœã§ãããã®æ¹æ³ã¯ãéåžžã®ã·ã§ã«/Perlã¹ã¯ ãªãããšåæ§ã«å®è¡ããããšãã§ããŸãã
|
The arguments passed to your script are available in the global array $argv.
|
衚 23-3ã³ãã³ãã©ã€ã³ãªãã·ã§ã³
|
The second registered global variable is $argc which contains the number of elements in the $argv array (not the number of arguments passed to the script).
|
ã«ã©ãŒæ§æãã€ã©ã€ã衚瀺ããããœãŒã¹ã衚瀺ããŸãã
|
Passing an argument to your script which starts with a - will cause trouble because PHP Passing an argument to your script which starts with a - will cause trouble because PHP itself thinks it has to handle it.
|
ãã®ãªãã·ã§ã³ã¯ããã¡ã€ã«ãããŒã¹ãã HTML ãã€ã©ã€ã衚瀺çã®ãã¡ã€ã«ãçæããæšæºåºåã«æžãåºãå
éšæ© æ§ã䜿çšããŸããè¡ãã®ã¯ã code [...] /code ã®ããã㯠ãçæããããšã ãã§ã HTML ãããã¯åºåãã ãªãããšã«æ³šæããŠäžããã
|
After this separator has been parsed by PHP, every argument following it is passed untouched to your script.
|
泚æ ãã®ãªãã·ã§ã³ã¯ã -r ãªãã·ã§ã³ãšåæã«äœ¿ çšããããšã¯ã§ããŸããã
|
You can write a script where the first line starts with #! / usr / bin / php.
|
ã³ã¡ã³ããšç©ºçœæåãåé€ããŠãœãŒã¹ã衚瀺ããŸãã
|
Once you have set the execution attributes of the file appropriately (e.g. chmod +x test) your script can be executed like a normal shell or perl script:
|
泚æ ãã®ãªãã·ã§ã³ã¯ã -r ãªãã·ã§ã³ãšåæã«äœ¿ çšããããšã¯ã§ããŸããã
|
$chmod 755 test $. / test -h - - foo array( 4) {[0]= string(6) ". / test" [1]= string(2) "-h "[2]= string(2) "- -" [3]= string(3) "foo "}
|
-f ãªãã·ã§ã³ã«æå®ãããã¡ã€ã«åãïŸïŸïœ°ïœœãã å®è¡ããŸãããã®ã¹ã€ããã¯ãªãã·ã§ã³ã§çç¥ããããšãã§ããŸãã å®è¡ããã¹ã¯ãªãããæå®ããã ãã§å
åã§ãã
|
Display colour syntax highlighted source.
|
PHP, PHP SAPI, Zendã®ããŒãžã§ã³ãæšæºåºåã«åºåããŸããäŸïŒ
|
Note that all it does it to generate a block of code [...] / code HTML tags, no HTML headers.
|
ãã®ãªãã·ã§ã³ã䜿çšããããšã«ããã php.ini ãæ¢ããã£ã¬ã¯ã ãªãæå®ããããã«ã¹ã¿ãã€ãºããã INI ãã¡ ã€ã«( php.ini ãšããååã§ããå¿
èŠã¯ãããŸãã)ãçŽæ¥æå®ãã ããšãå¯èœã§ããäŸïŒ
|
This switch is optional and can be left out.
|
PHPã察話çã«å®è¡ããŸãã
|
$php -v PHP 4.3.0 (cli), Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies
|
ãã®ãªãã·ã§ã³ã«ãã php.ini ã§æå®ã§ããèšå®ãã£ã¬ã¯ãã£ã ã«ã«ã¹ã¿ã å€ãèšå®ããããšãã§ããŸããæ§æã¯ä»¥äžã®ããã«ãªããŸãã
|
$php -c / custom / directory / my_script.php $php -c / custom / directory / custom-file.ini my_script.php
|
äŸ:
|
The syntax is:
|
ãããã¬/ãããã¡ã€ã©çšã®æ¡åŒµæ
å ±ãåºåããŸãã
|
Passing a filename with an absolute path information will not use the systems library search path.
|
ãã®ãªãã·ã§ã³ã«ãããæå®ãã PHP ã³ãŒãã® æ§æãã§ãã¯ã®ã¿ãç°¡åã«è¡ãªãããšãã§ããŸããæåããå Žåã ããã¹ã No syntax errors detected in filename ããæšæºåºåã«æžã蟌ãŸãããªã¿ãŒã³ã³ãŒã㯠0 ãšãªããŸãã倱æããå Žåãããã¹ã Errors parsing filename ã«å ããŠãå
éšããŒãµãšã©ãŒã¡ãã»ãŒãž ãæšæºåºåã«æžã蟌ãŸããã·ã§ã«ãªã¿ãŒã³ã³ãŒãã¯ã 255 ãšãªããŸãã
|
On failure, the text Errors parsing filename in addition to the internal parser error message is written to standard output and the shell return code is set to 255.
|
ãã®ãªãã·ã§ã³ã¯ã(æªå®çŸ©ã®é¢æ°ã®ãããª)èŽåœçãªãšã©ãŒ(fatal error) ã¯ã¿ã€ããŸãããèŽåœçãªãšã©ãŒã«ã€ããŠã調ã¹ããå Žåã¯ã -f ã䜿çšããŠãã ããã
|
Use -f if you would like to test for fatal errors too.
|
泚æ ãã®ãªãã·ã§ã³ã¯ããªãã·ã§ã³ -r ãšå
±ã«äœ¿çšããããšã¯ ã§ããŸããã
|
$php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules]
|
ãã®ãªãã·ã§ã³ã䜿çšãããšãPHPã¯ãPHPã«çµã¿èŸŒãŸãã (ãããŠããŒãããã) Zend ã¢ãžã¥ãŒã«ãåºåããŸãã
|
If PHP is not working correctly, it is advisable to use php -i and see whether any error messages are printed out before or in place of the information tables.
|
ãã®ãªãã·ã§ã³ã«ãããã³ãã³ãã©ã€ã³ã®ã¿ã§ PHP ã®å®è¡ãã§ããããã«ãªããŸãã PHP ã®éå§ããã³çµäºã¿ã° (?php ããã³?) 㯠äžèŠ ã§ãããããä»ãããš ããŒãµãšã©ãŒãšãªããŸãã
|
The PHP start and end tags (?php and?) are not needed and will cause a parser error if present.
|
泚æ ãã®ããã« PHP ãå®è¡ããéã«ãã³ãã³ãã©ã€ã³ã® 倿°ãã·ã§ã«ã«ããè¡ãªããã眮æãšå¹²æžããªãããã«æ³šæããŠäžããã
|
Example showing a parser error
|
ããŒãµãšã©ãŒãçããäŸ
|
The PHP executable can be used to run PHP scripts absolutely independent from the web server.
|
äŸ 23-1 ã³ãã³ãã©ã€ã³ããå®è¡ãããããšãæå³ããã¹ã¯ãªãã(script.php)
|
On a Windows platform you can associate php.exe with the double click option of the .php files, or you can make a batch file to run the script through PHP.
|
äžã®ã¹ã¯ãªããã§ã¯ãç¹æ®ãªå
é è¡ãçšããããŠããããã®ãã¡ã€ã«ã PHPã«ããå®è¡ãããããšã瀺ããŠããŸããããã§ã¯CLIçã䜿çšããŠããããã HTTPãããã¯åºåãããŸãããPHPã§ ã³ãã³ãã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ã䜿çšããéã«ã¯ã2ã€ã®å€æ° $argc and $argv ã䜿çšããããšã ã§ããŸãã æåã®å€æ°ã¯ãåŒæ°ã®æ°ã«1(å®è¡äžã®ã¹ã¯ãªããã®åå)ãå ãããã®ã§ãã 2çªç®ã®å€æ°ã¯ãåŒæ°ãä¿æããé
åã§ãã¹ã¯ãªããåãæãã èŠçŽ 0( $argv[0] )ããå§ãŸã£ãŠããŸãã
|
A simple example of writing a command line PHP program can be found below.
|
äžã®ããã°ã©ã ã§ã¯ãåŒæ°ã1ããå°ãªãããŸãã¯å€ããã調ã¹ãŠããŸãã ãŸããåŒæ°ã --help, -help, -h, -? ã®å Žåã ãã«ãã¡ãã»ãŒãžãåºåããåçã«ã¹ã¯ãªããåãåºåããŸãã ä»ã®åŒæ°ãåãåã£ãå ŽåããããåºåããŸãã
|
In the script above, we used the special first line to indicate that this file should be run by PHP.
|
äžã®ã¹ã¯ãªãããUnixã§å®è¡ããå Žåãå®è¡å¯èœãšããåŸã script.php echothis ãŸã㯠script.php -h ãšããå¿
èŠããããŸãã Windowsã§ã¯ããã®åŠçãè¡ãªã以äžã®ãããªããããã¡ã€ã«ãäœæããããšã ã§ããŸãã
|
Also if the argument was --help, -help, -h or -?, we printed out the help message, printing the script name dynamically.
|
äŸ 23-2 ã³ãã³ãã©ã€ã³PHPã¹ã¯ãªãããå®è¡ããããããã¡ã€ã«(script.bat)
|
If you would like to run the above script on Unix, you need to make it executable, and simply call it as script.php echothis or script.php -h.
|
äžã®ããã°ã©ã ã script.php ãšããååã§ãããš ãã c:\php\php.exe ã« php.exe ããããšãããšããã®ããããã¡ã€ã«ã¯ã远å ãããªãã·ã§ã³ script.bat echothis ãŸã㯠script.bat -h ãæå®ããŠãã¹ã¯ãªãããå®è¡ããŸãã
|
See also the Readline extension documentation for more functions you can use to enhance your command line applications in PHP.
|
PHPã®ã³ãã³ãã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ãæ¡åŒµããããã«äœ¿çšã§ãã ãã®ä»ã®é¢æ°ã«ã€ããŠã¯ãæ¡åŒµã¢ãžã¥ãŒã« Readline ã«é¢ãã ããã¥ã¡ã³ããåç
§ããŠãã ããã
|
If the PHP-imposed time limit (see set_time_limit()) is hit, the TIMEOUT state flag is turned on.
|
泚æ 以äžã¯ãPHP 3.0.7 ç以éã«é©çšãããŸãã
|
Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output.
|
PHP å
éšã§ãæ¥ç¶ã¹ããŒã¿ã¹ãä¿æãããŸãã ããã¯ã次㮠3 ã€ã®ç¶æ
ããšãããŸãã
|
When the timer expires the script will be aborted and as with the above client disconnect case, if a shutdown function has been registered it will be called.
|
éåžž PHP ãå®è¡ãããŠããå ŽåãNORMAL ç¶æ
ãã¢ã¯ãã£ãã«ãªããŸãã ãªã¢ãŒãã¯ã©ã€ã¢ã³ããæ¥ç¶ãåã£ãå ŽåãABORTED ç¶æ
ãã©ã°ãæå¹ã«ãªããŸãã éåžžããªã¢ãŒãã¯ã©ã€ã¢ã³ãã®æ¥ç¶æã¯ãSTOP ãã¿ã³ãæŒãããšã«ããçºçããŸãã PHP åŽã®æéå¶é (set_time_limit() åç
§) ã«ããã£ãå Žåã TIMEOUT ç¶æ
ãã©ã°ãæå¹ã«ãªããŸãã
|
Any cookies sent to you from the client will automatically be turned into a PHP variable just like GET and POST method data, depending on the register_globals and variables_order configuration variables.
|
ã¯ã©ã€ã¢ã³ãããéãããå
šãŠã®ã¯ãããŒã¯ã register_globals ã variables_order ã®èšå®å€ã«åŸã£ãŠã GET ã POST ã¡ãœããã®ããŒã¿ãšå
šãåæ§ã«èªåçã« PHP 倿°ã«å€æ ãããŸãã倿°ã®å€ãäžã€ã®ã¯ãããŒã«å²ãä»ãããå Žåã¯ã [] ãã¯ãããŒåã«å ããŠãã ããã
|
In PHP 4.1.0 and later, the $_COOKIE auto-global array will always be set with any cookies sent from the client. $HTTP_COOKIE_VARS is also set in earlier versions of PHP when the track_vars configuration variable is set.
|
PHP 4.1.0以éã§ã¯ãã¯ã©ã€ã¢ã³ãããéä¿¡ãããå
šãŠã®ã¯ãããŒã¯åžžã« $_COOKIE ãšãã(åžžã«ã°ããŒãã«ãª)é
åã«æ ŒçŽãããŸãã ãã以åã®ããŒãžã§ã³ã§ãã track_vars ãã»ãããããŠããã° $HTTP_COOKIE_VARS ã«ã¯ãããŒã®å
å®¹ãæ ŒçŽãããŸãã
|
Prev
|
ã¡ãã£ãšããæ³šæããã©ãŠã¶ã®ãã°ãšãã£ã詳现ã«é¢ããŠã¯ã setcookie() ãåç
§ããŠãã ããã
|
The default is 2 Megabytes.
|
MAX_FILE_SIZE ã« upload_max_filesize ã§æå®ããããã¡ã€ã«ãµã€ãºãã倧ããªãã¡ã€ã«ãµã€ãºãæå®ãã ããšã¯ã§ããŸãããããã©ã«ãã¯ã2ã¡ã¬ãã€ãã§ãã
|
Make sure to set memory_limit large enough.
|
ã¡ã¢ãªå¶éãæå¹ãªå Žåã memory_limit ã«ãã倧ããªå€ãèšå® ããããšãå¿
èŠãšãªãå¯èœæ§ããããŸãã memory_limit ã«å
å倧ããªå€ ãèšå®ããããã«ããŠäžããã
|
Make sure to set max_execution_time large enough.
|
max_execution_time ã«èšå®ããå€ãå°ããããå Žåãã¹ã¯ãªããã®å®è¡æéããã®å€ãè¶ãã å¯èœæ§ãçããŸãã max_execution_time ã«å
å倧ããªå€ãèšå®ãããã ã«ããŠäžããã
|
Make sure to set post_max_size large enough.
|
post_max_size ã®èšå®å€ãå° ããããå Žåã倧ããªãã¡ã€ã«ãã¢ããããŒãããããšãã§ããªããªã㟠ãã post_max_size ã«å
å倧ããªå€ãèšå®ããããã« ããŠäžããã
|
Please note that the CERN httpd seems to strip off everything starting at the first whitespace in the content-type mime header it gets from the client.
|
åŠçãããã¡ã€ã«ãæ€èšŒããªãå ŽåããŠãŒã¶ãŒãä»ã®ãã£ã¬ã¯ããªã«ãã éå
¬éæ
å ±ã«ã¢ã¯ã»ã¹ã§ããå¯èœæ§ãçããŸãã
|
Due to the large amount of directory listing styles we cannot guarantee that files with exotic names (like containing spaces) are handled properly.
|
CERN httpd ã¯ãã¯ã©ã€ã¢ã³ãããåŸã content-type MIME ãããã«ãã ãŠæåãç©ºçœæåã§å§ãŸããã®ãåãæšãŠãããã§ãã®ã§æ³šæããŠäžããã ãã®ãããªåäœãããéããCERN httpd ã¯ããã¡ã€ã«ã¢ããããŒãæ©èœã ãµããŒãããªãã§ãããã
|
The error code can be found in the ['error'] segment of the file array that is created during the file upload by PHP.
|
PHP 4.2.0以éãPHPã¯ãã¡ã€ã«é
åãšãšãã«é©åœãªãšã©ãŒã³ãŒããè¿ããŸãã ãšã©ãŒã³ãŒãã¯ãPHPã«ãããã¡ã€ã«ã¢ããããŒãã®éã«çæããã ãã¡ã€ã«é
åã® ['error'] èŠçŽ ã§ ã¢ã¯ã»ã¹å¯èœã§ããèšãæãããšããšã©ãŒã¯ã $_FILES['userfile']['error'] ã§ã¢ã¯ã»ã¹å¯èœã§ãããã
|
Value:
|
å€: 0; ãšã©ãŒã¯ãªãããã¡ã€ã«ã¢ããããŒãã¯æåããŠããŸãã
|
Value:
|
å€: 1; ã¢ããããŒãããããã¡ã€ã«ã¯ã php.ini ã® upload_max_filesize ãã£ã¬ã¯ãã£ãã®å€ãè¶
ããŠããŸãã
|
Value:
|
å€: 2; ã¢ããããŒãããããã¡ã€ã«ã¯ãHTMLãã©ãŒã ã§æå®ããã MAX_FILE_SIZE ãè¶
ããŠããŸãã
|
Value:
|
å€: 3; ã¢ããããŒãããããã¡ã€ã«ã¯äžéšã®ã¿ããã¢ããããŒããããŠããŸããã
|
Value:
|
å€: 4; ãã¡ã€ã«ã¯ã¢ããããŒããããŸããã§ããã
|
Prev
|
泚æ ãããã¯PHP 4.3.0ã§PHP宿°ãšãªããŸããã
|
Related Configurations Note:
|
é¢ä¿ããèšå®ã«é¢ããæ³šèš php.ini ã® file_uploads, upload_max_filesize, upload_tmp_dir post_max_size ãã£ã¬ã¯ãã£ã ãåç
§äžããã
|
Note that PHP also supports PUT-method file uploads as used by Netscape Composer and W3C 's Amaya clients.
|
PHPã¯Netscape Composerããã³W3Cã®Amayaã¯ã©ã€ã¢ã³ãã«ãã䜿çšããã PUTã¡ãœããã«ãããã¡ã€ã«ã¢ããããŒãããµããŒãããŠããããšã«æ³šæ ããŠäžããã詳现ã¯ã PUTã¡ãœããã®ãµããŒã ãåç
§äžããã
|
A file upload screen can be built by creating a special form which looks something like this:
|
ãã¡ã€ã«ã¢ããããŒãç»é¢ã¯ã次ã®ãããªç¹å¥ãªãã©ãŒã ãäœæããããš ã«ãããäœæããããšãã§ããŸãã
|
File Upload Form
|
äŸ 18-1ãã¡ã€ã«ã¢ããããŒãçšã®ãã©ãŒã
|
Warning
|
MAX_FILE_SIZEã¯ãã©ãŠã¶ãžã®å§åã«éããŸããããã®æå€§å€ã åºãæãã®ã¯ç°¡åãªããšãªã®ã§ä¿¡é ŒããŠã¯ãããŸããããããã PHPåŽã®æå€§ãµã€ãºã®èšå®ã欺ãããšã¯ã§ããŸããã
|
The autoglobal $_FILES exists as of PHP 4.1.0 The $HTTP_POST_FILES array has existed since PHP 4.0.0.
|
$_FILES ã®å
å®¹ã¯æ¬¡ã®ããã«ãªããŸããããã§ã¯ãäžã®äŸã®ã¹ã¯ãªããã§äœ¿ãããããã«ã ã¢ããããŒããã¡ã€ã«ã®ååãšã㊠userfile ã䜿çšãã ããšãä»®å®ããŠããããšã«æ³šæããŠäžããã
|
Using $_FILES is preferred.
|
ã¯ã©ã€ã¢ã³ããã·ã³ã®å
ã®ãã¡ã€ã«åã
|
The contents of $_FILES from our example script is as follows.
|
ãã¡ã€ã«ã®MIMEåããã ãããã©ãŠã¶ããã®æ
å ±ãæäŸããå Žåã äŸãã°ã "image/gif" ã®ããã«ãªããŸãã
|
The original name of the file on the client machine.
|
ã¢ããããŒãããããã¡ã€ã«ã®ãã€ãåäœã®ãµã€ãºã
|
The error code associated with this file upload. ['error'] was added in PHP 4.2.0
|
ã¢ããããŒãããããã¡ã€ã«ããµãŒããŒäžã§ä¿åãããŠãããã³ãã© ãªãã¡ã€ã«ã®ååã
|
PHP 3 does not support $HTTP_POST_FILES.
|
ãã®ãã¡ã€ã«ã¢ããããŒãã«é¢ãã ãšã©ãŒã³ãŒã ['error'] ã¯ãPHP 4.2.0ã§è¿œå ãããŸããã
|
For example, $userfile_name will equal $_FILES[ 'userfile']['name'], $userfile_type will equal $_FILES['userfile']['type'], etc.
|
泚æ 4.1.0ããåã®ããŒãžã§ã³ã®PHPã§ã¯ããã®å€æ°ã¯ $HTTP_POST_FILES ã§ã $_FILES ã® ãã㪠ãªãŒãã°ããŒãã« å€æ°ã§ã¯ãããŸããã§ãããPHP 3ã¯ã $HTTP_POST_FILES ããµããŒãããŠããŸããã
|
The server 's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs.
|
php.ini ã§ register_globals ã on ãšãªã£ãŠããå Žåã远å ã®å€æ°ãå©çšå¯èœãšãªããŸãã äŸãã°ã $userfile_name ã¯ã $_FILES['userfile']['name'] ãšåãã§ã $userfile_type ã¯ã $_FILES['userfile']['type'] ãšåããšãã£ãããã«ãªããŸãã PHP 4.2.0以éã¯ãregister_globalsã®ããã©ã«ãã¯offã§ããããšã çæäžããããã®ãã£ã¬ã¯ãã£ãã«äŸåããªãããšãæšå¥šãããŸãã
|
Here' s some debugging info:\n"; print_r($_FILES);}?
|
äŸ 18-2ãã¡ã€ã«ã®ã¢ããããŒããæ€èšŒãã
|
You can for example use the $_FILES[ 'userfile']['size'] variable to throw away any files that are either too small or too big.
|
以äžã®äŸã¯ã4.0.2 ããåŸã®ããŒãžã§ã³ã® PHP 4 çšã§ãã is_uploaded_file() ããã³ move_uploaded_file() ã®é¢æ°ã®ãšã³ããªã åç
§äžããã
|
The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
|
ç§»åãŸãã¯ååã®å€æŽãè¡ãããŠããªãå Žåããªã¯ãšã¹ãã®çµäºæã«ãã® ãã¡ã€ã«ã¯ãã³ãã©ãªãã£ã¬ã¯ããªããåé€ãããŸãã
|
It is obviously not a good idea for Apache or PHP to automatically let everybody overwrite any files in your web tree.
|
PHP ã¯ãNetscape Composer ã W3C Amaya ã®ãããªã¯ã©ã€ã¢ã³ãã§ ãµããŒãããã HTTP PUT ã¡ãœããããµããŒãããŸãã PUT ãªã¯ãšã¹ãã¯ããã¡ã€ã«ã¢ããããŒããããããªãç°¡åã§ããã æ¬¡ã®ãããªãã®ã«ãªããŸãã
|
The only trick here is that when PHP sees a PUT-method request it stores the uploaded file in a temporary file just like those handled but the POST-method.
|
ããã«ããããã®è¡ãæå®ããã³ã³ããã¹ãã«ãããããURIãæããå
š ãŠã®PUTãªã¯ãšã¹ãã put.php ã¹ã¯ãªããã«éããããã Apache ã«æ å®ããŸãã ãã¡ãããæ¡åŒµå .php ã«ãã PHP ãå®è¡ãããããèšå® ãããPHP ãã¢ã¯ãã£ãã§ããããšãå¿
èŠã§ãã
|
So, your PUT handling PHP script has to copy that file somewhere.
|
put.php ãã¡ã€ã«ã®äžã§æ¬¡ã®ããã«åŠçãè¡ãå¿
èŠããããŸãã
|
Only "Basic" authentication is supported.
|
PHP ããŒãžã§ã³ã«é¢ããæ³šæ $_SERVER ã®ãã㪠ãªãŒãã°ããŒãã« ã¯ã PHPããŒãžã§ã³ 4.1.0 ã§å©çšå¯èœã§ãã $HTTP_SERVER_VARS ã¯ãPHP 3以éã§å©çšå¯èœã§ãã
|
An example script fragment which would force client authentication on a page is as follows:
|
ããŒãžäžã§ã¯ã©ã€ã¢ã³ãèªèšŒã匷å¶ããã¹ã¯ãªããã®äŸã以äžã«ç€ºããŸãã
|
HTTP Authentication example
|
äŸ 16-1HTTP èªèšŒã®äŸ
|
Basic realm=" My Realm"'); header('HTTP / 1.0 401 Unauthorized'); echo'Text to send if user hits Cancel button'; exit;} else {echo "p Hello {$_SERVER['PHP_AUTH_USER']}. / p"; echo "p You entered {$_SERVER['PHP_AUTH_PW']} as your password. / p";}?
|
äºæè£œã«é¢ããæ³šæ HTTPãããè¡ãã³ãŒãã£ã³ã°ããéã«ã¯æ³šæãèŠããŸããå
šãŠã®ã¯ã©ã€ã¢ ã³ããžã®äºææ§ãæå€§éã«ä¿èšŒããããã«ãããŒã¯ãŒã "Basic" ã«ã¯ã 倧æåã®"B"ã䜿çšããŠæžãã¹ãã§ããrealmæååã¯(äžéåŒçšç¬Šã§ã¯ãª ã)äºéåŒçšç¬Šã§æ¬ãå¿
èŠããããŸãããŸãã"HTTP/1.0 401"ãããè¡ã® ã³ãŒã"401"ã®åã«ã¯ã1ã€ã ã空çœã眮ãå¿
èŠããããŸãã
|
Perhaps by sending a query to a database, or by looking up the user in a dbm file.
|
ãã°ã®ãã Internet Explorer ãã©ãŠã¶ã«ã¯æ³šæããŠãã ããããã®ãã© ãŠã¶ã¯ããããã®é åºã«é¢ããŠãšãŠãããããããã§ããä»ã®ãšããã HTTP/1.0 401 ãããã®åã« WWW-Authenticate ããããéãã®ã广ãããã ãã§ãã
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.