【发布时间】:2015-08-28 18:21:42
【问题描述】:
所以我有一个 html 表单,它正在传递我的图片(实际名称),但这就是我所能得到的。当我尝试获取 tmp_name 或类似的任何内容时,它会显示错误。
另外,如果我的 html 表单没有声明 enctype,我只能获取文件的名称。
HTML
<form action="{{ urlFor('account.profile.post') }}" method="post" autocomplete="off">
<!-- OTHER TEXT INPUTS THAT OUTPUT PERFECTLY FINE -->
<div class="form-group">
<label for="propic">Profile picture</label>
<input type="file" id="propic" name="propic">
</div>
</form>
PHP
if($app->request->params('propic') != null) {
$propic = $app->request->post('propic');
$target_dir = "profs/$img_salt/";
$target_file = $target_dir.$propic;
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
if (move_uploaded_file($propic["tmp_name"], $target_file)) {
echo "The file ". basename( $propic["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
【问题讨论】:
-
你遇到了什么错误?
标签: php html forms file-upload slim