我的意思是我这里有这段代码,该文件上传带有图像的文件,在托管它后在我的本地主机上运行良好,我意识到我没有得到图像预览,但是它在数据库中的发布非常好
我已经将其托管在一个实时网站上,正如我所说的,它在我的本地主机上运行得很好
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/images/');
if (!empty($_FILES)){
$photo = $_FILES['description_image'];
$name = $photo['name'];
$nameArray = explode('.',$name);
$fileName = $nameArray[0];
$fileExt = $nameArray[1];
$mime = explode('/',$photo['type']);
$mimeType = $mime[0];
$mimeExt = $mime[1];
$tmpLoc = $photo['tmp_name'];
$fileSize = $photo['size'];
$allowed = array('png','jpg','jpeg','gif','mp4','mp3','wma','MP4');
$uploadName = md5(microtime()).'.'.$fileExt;
$uploadPath = BASEURL.'/images/uploads/'.$uploadName;
$dbpath = '/holyfamilycatholicchurch-
foso.com/httpdocs/images/uploads/'.$uploadName;
/*if($mimeType != 'image'){
$errors[] = 'The file must be an image.';
}*/
/*if(!in_array($fileExt, $allowed)){
$errors[] = 'The File extension must be a png, jpg, jpeg or gif,
mp4, mp3, wma, MP4';
}*/
if($fileSize > 1500000000){
$errors[] = 'The file size must be under 15MB';
}
if($fileExt != $mimeExt && ($mimeExt == 'jpeg' && $fileExt !=
'jpg')){
$errors[] = 'File extension does not match the file.';
}
}
if(!empty($errors)){
echo display_errors($errors);
}else{
//upload files into db
move_uploaded_file($tmpLoc,$uploadPath);
$insert_post = "INSERT INTO posts
(`title`,`post_cat`,`description`,`description_image`,`main_content`,`date_posted`) VALUES ('$title','$post_cat','$description','$dbpath','$main_content',now())";
$insert_pst = mysqli_query($con, $insert_post);
if($insert_pst){
echo "<script>alert('Post has been inserted')</script>";
echo "<script>window.open('new_post.php?insert_product','_self')
</script>";
}
}
}
我希望图像输出
答案 0 :(得分:0)
尝试替换您的第一个变量:
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/images/');
带有标准变量声明:
$BASEURL = $_SERVER['DOCUMENT_ROOT'] . "/images/" ;
请确保每次致电$BASEURL
时都以$
开头。我注意到您在没有BASEURL
的情况下致电$
。