我正在尝试将文件上传到我的网站,但由于某种奇怪的原因它不起作用。存在=true 正在触发,所以这意味着它应该工作正常吗?它给了我$error=true;。下面是我的代码:
.HTML:
<input size="30" enctype="multipart/form-data" name="profile_icon" id="register-profile_icon" class="elgg-input-file" type="file">
.PHP:
$profile_icon = $_FILES["profile_icon"];
if($profile_icon){
$exists=true;
}
$error = false;
if(empty($profile_icon["name"])){
register_error(elgg_echo("profile_manager:register_pre_check:missing", array("profile_icon")));
$error = true;
}
使用 $_FILES["profile_icon"]["tmp_path"]
作为文件路径。
$_FILES["profile_icon"]
这将包含名称、tmp_path、类型、大小等值数组。
另一方面,您需要将enctype
属性添加到您的<form>
中。
并且有可用于移动上传功能的功能move_uploaded_file();