这似乎是一个大问题,确实如此,但大多数都完成了,但我迷失在真正到达我想去的地方。
我已经准备好上传表单并且它可以工作,它将它保存到一个名为 upload 的文件夹中,但我需要它来根据我会话中保存的酒店名称创建一个文件夹。这显示在页面上,以告诉用户他们正在进行的会话。所以现在当他们保存时,我需要它来创建以它命名的文件夹以将其保存到该目录。所以这里是 HTML 的代码:
<span class="prettyFile">
<form id="form" action="assets/php/upload.php" method="post" enctype="multipart/form-data">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3" style="margin-top: -3px;"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div><span class="btn btn-file btn-success"><span class="fileupload-new">Upload File</span><span class="fileupload-exists">Change</span><input type="file" name="file" /></span><a href="#" class="btn fileupload-exists btn-success" style="margin-top: -3px;" data-dismiss="fileupload">Remove</a>
<button type="submit" name="submit" class="btn btn-primary fileupload-exists" value="Upload"><i class="icon-cloud-upload"></i> Upload</button>
</div>
</div>
</form>
</span>
这是PHP:
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 10000000)
&& in_array($extension, $allowedExts))
if (file_exists("upload/". $_SESSION['curHotelName'] . "/" . $_FILES["file"]["name"]))
{
echo "<script language='javascript'>\n";
echo "alert('This file exists! Please select a different file.'); window.location.href='https://hotelmobidev.jvgames.com/profile';";
echo "</script>\n";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/". $_SESSION['curHotelName'] . "/" . $_FILES["file"]["name"]);
echo "<script language='javascript'>\n";
echo "alert('Success!'); window.location.href='https://hotelmobidev.jvgames.com/profile';";
echo "</script>\n";
}
?>
我还在搞砸它,但如果有人能把我撞到正确的方向,那就太棒了!多谢你们!