[英]File won't upload in PHP
我在IIS上安裝了php,並嘗試在CakePHP中實現文件上傳。
我已經遵循了文件上傳的必要准則,但是每次上傳時,我都會不斷收到以下內容並帶有uploadError
。 可能是錯誤的,即使temp_name
為空。
最初以為IIS沒有對該臨時文件夾的寫權限,但是即使獲得了IIS_IUSRS
和IUSR
完全權限,它也無法正常工作
array(5) {
["name"]=>
string(14) "DSC02474_2.JPG"
["type"]=>
string(0) ""
["tmp_name"]=>
string(0) ""
["error"]=>
int(1)
["size"]=>
int(0)
}
形成
<?php
echo $this->Form->create('User', array('class'=>'form-horizontal', 'action'=>'uploadProfilePicture', 'id'=>'change-picture', 'type'=>'file'));
echo $this->Form->input('id', array('value'=>$authUser['id']));
echo $this->Form->file('picture');
?>
<input type="submit" value="Upload" class="btn btn-info" name="submit">
<?php echo $this->Form->end(); ?>
模型處理
public function uploadFile( $check ) {
$uploadData = array_shift($check);
if ( $uploadData['size'] == 0 || $uploadData['error'] !== 0) {
return false;
}
$uploadFolder = APP.'uploads'.DS."profile-pictures";
$fileName = time()."_".$uploadData['name'];
$uploadPath = $uploadFolder . DS . $fileName;
if( !file_exists($uploadFolder) ){
mkdir($uploadFolder);
}
if (move_uploaded_file($uploadData['tmp_name'], $uploadPath)) {
$this->set('picture', $fileName);
return true;
}
return false;
}
我剛剛在http://php.net/manual/en/function.is-uploaded-file.php上找到了解決問題的方法。
如果您的$ _FILES和$ _POST為空,則可能是由於
不幸的是,第一個限制沒有在$ _FILES ['error']中報告為錯誤代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.