图片已上传,但我看不到 [英] images are uploaded but I can't see them
问题描述
我正在CMS网站上工作, 图片已上传,但我看不到,它显示了我
I'm working at a CMS website , images are uploaded but i can't see them , and it shows me
在Inspect元素中,它向我显示无法加载给定的URL"或无法加载响应数据" ....或
In Inspect element its show me "failed to load the given URL" or "Failed to load response data" .... or
无法加载资源:服务器的响应状态为404(未找到)jpg
Failed to load resource: the server responded with a status of 404 (Not Found) jpg
我会在这里放一些工具,也许你们会帮我解决这个问题,因为我完成了!我不知道了
I will put here some tools , maybe you guys will help me to fix this out , because I'm done !I can't figure out
[![在此处输入图片描述] [1]] [1]
[![enter image description here][1]][1]
<?php if(isset($opened['id'])){ ?>
<script>
$(document).ready(function() {
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#avatar-dropzone");
// myDropzone.on("success", function(file){
// $('#avatar').load("ajax/avatar.php?id=<?php echo $opened['id'];?>");
// });
});
</script>
<?php } ?>
<h1>User Manager</h1>
<div class="row">
<div class="col-md-3">
<div class="list-group">
<a class="list-group-item" href="?page=users">
<i class="fa fa-plus"></i> New User
</a>
<?php
$q = "SELECT * FROM users ORDER BY last ASC";
$r = mysqli_query($dbc, $q);
while($list = mysqli_fetch_assoc($r)) {
$list = data_user($dbc, $list['id']);
//$blurb = substr($page_list['body'], 0, 300); // scoate decat primele 200 de caractere!
?>
<a class="list-group-item <?php selected($list['id'], $opened['id'], 'active'); ?>" href="index.php?page=users&id=<?php echo $list['id']; ?>">
<h4 class="list-group-item-heading"><?php echo $list['fullname_reverse'];?></h4>
<!-- <p class="list-group-item-text"><?php #echo $blurb; ?></p>-->
</a>
<?php } ?>
</div>
</div>
<div class="col-md-9">
<?php if(isset($message)) { echo $message; } ?>
<!--Caracteristicile editabile ale paginilor-->
<form action="index.php?page=users&id=<?php echo $opened['id']; ?>" method="post" role="form">
<?php if($opened['avatar'] != '') { ?>
<img src="http://localhost/mywebsite/dinamiccms/uploads/<?php echo $opened['avatar']; ?>">
<?php if(isset($opened['id'])){ ?>
<form action="uploads.php?id=<?php echo $opened['id']; ?>" class="dropzone" id="avatar-dropzone">
<div class="fallback">
<input type="file" name="file">
</div>
</form>
<?php } ?>
</div>
</div>
----------我的htaccess
---------- my htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
-------和我的uploads.php
-------and my uploads.php
<?php
include('../config/connection.php');
$ds = DIRECTORY_SEPARATOR; //1
$id = $_GET['id'];
$storeFolder = "../uploads"; //2
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$newname = time();
$random = rand(100,999);
$name = $newname.$random.'.'.$ext;
$q = "UPDATE users SET avatar = '$name' WHERE id = $id";
$r = mysqli_query($dbc, $q);
//echo $q.'<br>';
//echo mysqli_error($dbc);
if(!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname(__FILE__). $ds. $storeFolder. $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile, $targetFile); //6
}
?>
我想提到我使用dropzonejs,但是我认为这没关系,因为我的图片已上传,并存储在该文件夹中,但我无法查看它们.我与数据库的连接正确.
I want to mention that i use dropzonejs but i think it doesn't matter because my images are uploaded , stored in that folder , but I can't view them. My connections with database are right .
这是我的文件夹的外观,但是我试图更改路径,但仍然遇到相同的问题.
That is how my folder looks , but i've tried to change the paths and still getting the same problem.
**稍后我发现了问题!
**Later EDIT : I found the problem !
if(!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname(__FILE__). $ds. $storeFolder. $ds; //4
$targetFile = $targetPath. $name; //5
move_uploaded_file($tempFile, $targetFile); //6
}
问题出在这里,而不是
$targetFile = $targetPath. $name; //5
我有
$targetFile = $targetPath. $_FILES['file']['name']; //5
更明确的是,当我上传图像时,该图像的转换名称在我的数据库中运行良好,但是它在我的上传文件夹中的图像名称发生了不同的变化,因此它与数据库中的名称不匹配.与文件夹/路径... 谢谢您的支持,当我在编程中长大后,我也会尝试帮助他人!**
More explicit , When I upload the image , the converted name of that image goes well in my database , but It changed diferently the name of the image in my upload folder ...so It won't match the names from database with folder/path ... THANK YOU for your support , I will try to help others too when I Will grow up in programming !**
推荐答案
尝试一下 在您的图片标签中src =在此将ci函数用作具有img名称的base_url()/pathname",并将您的图片上传到资产/上传中.这样就可以访问.
try this in your image tag src="use here ci function as base_url()/pathname with img name" and also upload your image into asset/upload. so can access.
这篇关于图片已上传,但我看不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!