我一直试图找到一个可以提供帮助的线程,并尝试了我能找到的所有解决方法。
我有一个上传文件的页面,可以是任何类型,并且它有效。我决定在另一个页面上使用相同的功能,但$ _FILES数组始终为空。
形式:
<form method="post" class="mainForm" enctype="multipart/form-data">
<fieldset>
<div class="widget first">
<div class="rowElem">
<label for="file">Upload Profile Picture</label>
<div class="formRight">
<input type="file" id="profilepicture" name="profilepicture" />
<button formaction="profile_pic.php" class="greyishBtn">Upload</button>
</div>
</div>
</fieldset>
</form>
PHP:
$name_first = "John";
$name_last = "Doe";
$folder_name = $name_last . "-" . $name_first . "-ID-" . $id . "/";
$dirname = "profile/" . $folder_name;
if(!is_dir($dirname)){
mkdir($dirname);
}
$dirname = $dirname . $_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'], $dirname)){
header("location:profile.php");
}
else{
echo $dirname;
}
?>
echo $dirname
只显示没有文件名的文件夹。
答案 0 :(得分:4)
嗯,您的输入文件名为name='profilepicture'
尝试:
$dirname = $dirname . $_FILES['profilepicture']['name'];
和
if(move_uploaded_file($_FILES['profilepicture']['tmp_name'], $dirname)){
header("location:profile.php"); }
答案 1 :(得分:2)
试试这段代码:
$name_first = "John";
$name_last = "Doe";
$folder_name = $name_last . "-" . $name_first . "-ID-" . $id . "/";
$dirname = "profile/" . $folder_name;
if(!is_dir($dirname)){
mkdir($dirname);
}
$dirname = $dirname . $_FILES['profilepicture']['name'];
if(move_uploaded_file($_FILES['profilepicture']['tmp_name'], $dirname)){
header("location:profile.php");
}
else{
echo $dirname;
}