我正在努力让用户将自己的缩略图上传到我的网站。我的代码是
$allowedExts = array("jpg", "jpeg", "gif", "png");
$explode = explode(".", $_FILES["file"]["name"]);
$extension = end($explode);
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "images/jpg")) && ($_FILES["file"]["size"] < 50000) && in_array($extension, $allowedExts))
{
$sDate = date("m-d-Y");
$sRandString = randomString(50);
$sFileName = rename($_FILES["file"]["tmp_name"], $sDate . $sUsername . $sRandString); //The name of the file
$sTargetLink = $_PARAM["ThumbnailDir"] . $sFileName;
if ($_FILES["file"]["error"] > 0)
echo "There has been an unexpected error, we're working on fixing it as soon as possible. Please try again later.";
else
{
if (file_exists($_PARAM["ThumbnailDir"] . $sFileName))
{
unlink($_PARAM["ThumbnailDir"] . $sFileName);
$sFileLocation = $_PARAM["WebsiteAddress"]."images/thumbnails/".$sFileName; //The location of the file
move_uploaded_file($_FILES["file"]["tmp_name"],$_PARAM["ThumbnailDir"] . $sFileName);
echo "The thumbnail has been successfully uploaded.";
unlink($_FILES["file"]["tmp_name"]);
}
else
{
$sFileLocation = $_PARAM["WebsiteAddress"] . "images/thumbnails/" . $sFileName; //The location of the file
$move = move_uploaded_file($_FILES["file"]["tmp_name"], $sTargetLink);
if ($move) echo "The thumbnail has been successfully uploaded.";
unlink($_FILES["file"]["tmp_name"]);
}
}
}
然后链接位置将保存在数据库中,允许可检索到图像的链接。但是,无论何时提交,页面都会返回:
警告:move_uploaded_file(C:\xampp\xxxxx\php3D71.tmp):打开流失败:第 117 行的 C:\xampp\xxxxxxx\xxxxx\xxxx.php 中没有这样的文件或目录
警告:move_uploaded_file(): Unable to move 'C:\xampp\xxxxx\php3D71.tmp' to 'C:\xampp\xxx\xxx\thumbnails1' in C:\xampp\xxxxxxxxx\xxx\xx\x.php on第 117 行
我不知道出了什么问题。表格是 enctype="multipart/form-data" 有什么建议吗?谢谢你。