php - 在我的实时网站中查看我的图片帖子时遇到问题
问题描述
我的意思是我在这里有这个代码,它可以上传带有图像的文件,它在托管它后在我的本地主机上运行良好我意识到我没有得到图像预览,但它在数据库中发布得很好
我已经将它托管在一个实时网站上,正如我所说,它在我的本地主机上运行得很好
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>";
}
}
}
我期望图像的输出
解决方案
尝试替换您的第一个变量:
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/images/');
使用标准变量声明:
$BASEURL = $_SERVER['DOCUMENT_ROOT'] . "/images/" ;
确保无论何时调用$BASEURL
它都会以$
. 我注意到你打电话时BASEURL
没有$
.
推荐阅读
- php - 将 html 输入作为 php 的变量
- git - 如何修复 git-lfs 服务器(gitlab)上损坏的文件?
- javascript - JavaScript中反射的概念是什么?
- android - Android 服务在 BOOT 上没有从 JobIntentService 开始
- java - JDeveloper 不允许创建新的 WebTier 项目
- twitter-bootstrap - Bootstrap 4 - 中心按钮
- java - 无论如何在apache httpclient中重试/重复消费的POST请求?
- java - 将 json 有效负载值合并到 Object
- c# - 如何在没有数据库的情况下将业务对象与 RDLC 设计器绑定?
- oracle - Oracle 程序中的“IS”有什么作用?