首页 > 解决方案 > 在我的实时网站中查看我的图片帖子时遇到问题

问题描述

我的意思是我在这里有这个代码,它可以上传带有图像的文件,它在托管它后在我的本地主机上运行良好我意识到我没有得到图像预览,但它在数据库中发布得很好

我已经将它托管在一个实时网站上,正如我所说,它在我的本地主机上运行得很好

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>";
}
}
}

我期望图像的输出

标签: php

解决方案


尝试替换您的第一个变量:

define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/images/');

使用标准变量声明:

$BASEURL = $_SERVER['DOCUMENT_ROOT'] . "/images/" ;

确保无论何时调用$BASEURL它都会以$. 我注意到你打电话时BASEURL没有$.


推荐阅读