我有IIS上的PHP安裝程序,並試圖在CakePHP內實現文件上傳。文件不會上傳在PHP
我已經遵循了文件上傳的必要準則,但每次上傳時,我都會收到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)
}
FORM
<?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(); ?>
HANDLER IN MODEL
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;
}
您可以添加您使用的表單代碼嗎? –
完成!編輯問題 – yomexzo