【发布时间】:2021-09-29 02:06:05
【问题描述】:
我有一个带有 php 的图像上传脚本,它可以在 localhost 服务器中工作,但是当我将网站上传到我的域服务器时,它会上传图像,但不会在 spathfic 文件夹中,我将其设置得很好,将文件夹路径设置为图片名称如
路径是
admin\upload\novelimage
图片名称会是这样的
upload\novelimage\...image that uploaded
如果脚本或服务器出错,我不知道,但我没有看到他们那边需要上传权限,所以我猜问题出在脚本上 这是脚本
//upload files
$avatarname = $_FILES['NovelImage']['name'];
$avatarsize = $_FILES['NovelImage']['size'];
$avatartmp = $_FILES['NovelImage']['tmp_name'];
$avatartype = $_FILES['NovelImage']['type'];
$avatarAllowedextention = array("jpeg", "jpg", "png", "gif");
//get avatar extention
$avatarextention = strtolower(end(explode('.', $avatarname)));
#get the varibles from the form
$Novelname = $_POST['Novelname'];
$Describe = $_POST['Describe'];
$category = $_POST['langOpt3'];
// condtion ? true and false
//check username
$formerrors = array();
if (! empty($avatarname) && ! in_array($avatarextention, $avatarAllowedextention)) {
$formerrors[] = 'avatar extension is not allowed';
}
if (empty($avatarname)) {
$formerrors[] = 'empty avatar is not allowed';
}
if ($avatarsize > 4194304) {
$formerrors[] = 'avatar size is bigger than 4mb';
}
foreach ($formerrors as $error) {
echo '<div class="alert alert-danger">' . $error . '</div>';
}
if (empty($formerrors)) {
$avatar = rand(0, 1000000) . '_' . $avatarname;
move_uploaded_file($avatartmp, "upload\novelimage\\" . $avatar);
$check = checkitem("NovelName", "novel", $Novelname);
if ($check == 1) {
$theMsg = "<div class='alert alert-danger'>sorry this user name is exit</div>";
redirecthome($theMsg, 'back');
}else{
//insert userinfo into database whith this info
$stmt = $con->prepare("INSERT INTO novel(NovelName, NovelImage, description)
VALUES(:znovel, :zNovelImage, :zdescription)");
$stmt->execute(array(
'znovel' => $Novelname,
'zNovelImage' => $avatar,
'zdescription' => $Describe
));
$lastid = $con->LastInsertId();
$stmt = $con->prepare("INSERT INTO book_category(novelid, categoryID)
VALUES(:znovelid, :zcategoryID)");
foreach ($category as $cat) {
$stmt->execute(array(
'znovelid' => $lastid,
'zcategoryID' => $cat
));
}
}
//erg
$theMsg = "<div class='alert alert-success '>" . $stmt->rowCount(). 'Record Updated</div>';
redirecthome($theMsg, 'back', 100);
}
我真的看不出有什么问题,请帮忙
【问题讨论】:
-
您需要比“一些错误”更具体。见How to Ask