Changeset 1240
- Timestamp:
- 11/05/06 01:01:13 (2 years ago)
- Location:
- trunk/src/request
- Files:
-
- 1 removed
- 1 modified
-
AgaviRestRequest.class.php (deleted)
-
AgaviWebRequest.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/request/AgaviWebRequest.class.php
r1239 r1240 67 67 68 68 /** 69 * @var bool Indicates whether or not PUT was used to upload a file. 70 */ 71 protected $isHttpPutFile = false; 72 73 /** 69 74 * Retrieve the scheme part of a request URL, typically the protocol. 70 75 * Example: "http". … … 461 466 parent::initialize($context, $parameters); 462 467 463 $methods = array('GET' => 'read', 'POST' => 'write' );468 $methods = array('GET' => 'read', 'POST' => 'write', 'PUT' => 'create', 'DELETE' => 'remove'); 464 469 if(isset($parameters['method_names'])) { 465 470 $methods = array_merge($methods, (array) $parameters['method_names']); … … 470 475 $this->setMethod($methods['POST']); 471 476 break; 477 case 'PUT': 478 $this->setMethod($methods['PUT']); 479 break; 480 case 'DELETE': 481 $this->setMethod($methods['DELETE']); 482 break; 472 483 default: 473 484 $this->setMethod($methods['GET']); 474 485 } 475 486 487 if($this->getMethod() == $methods['PUT']) { 488 // PUT. We now gotta set a flag for that and populate $_FILES manually 489 $this->isHttpPutFile = true; 490 491 $putfile = tmpfile(); 492 493 stream_copy_to_stream(fopen("php://input", "rb"), $putFile); 494 495 // for temp file name and size 496 $putFileInfo = array( 497 'stat' => fstat($putFile), 498 'meta_data' => stream_get_meta_data($putFile) 499 ); 500 501 $putFileName = isset($parameters['PUT_file_name']) ? $parameters['PUT_file_name'] : 'put_file'; 502 503 $_FILES = array( 504 $putFileName => array( 505 'name' => $putFileName, 506 'type' => 'application/octet-stream', 507 'size' => $putFileInfo['stat']['size'], 508 'tmp_name' => $putFileInfo['meta_data']['uri'], 509 'error' => UPLOAD_ERR_OK 510 ) 511 ); 512 } 513 476 514 $this->urlScheme = 'http' . (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 's' : ''); 477 515 … … 516 554 // merge POST parameters 517 555 $this->setParameters($_POST); 556 } 557 558 /** 559 * Wrapper method for either move_uplaoded_file or HTTP PUT input handling. 560 * 561 * @param string The name of the input file. 562 * @param string The name of the destination file. 563 * 564 * @return bool Whether or not the operation was successful. 565 * 566 * @author David Zuelke <dz@bitxtender.com> 567 * @since 0.11.0 568 */ 569 protected function moveUploadedFile($source, $destination) 570 { 571 if($this->isHttpPutFile) { 572 return @rename($source, $destination); 573 } else { 574 return @move_uploaded_file($source, $destination); 575 } 518 576 } 519 577 … … 568 626 } 569 627 570 if( @move_uploaded_file($_FILES[$name]['tmp_name'], $file)) {628 if($this->moveUploadedFile($_FILES[$name]['tmp_name'], $file)) { 571 629 // chmod our file 572 630 @chmod($file, $fileMode);

