图像上传但我看不到它们

时间:2021-12-26 15:07:12

I'm working at a CMS website , images are uploaded but i can't see them , and it shows me

我在CMS网站上工作,图片上传但我看不到它们,它显示了我

In Inspect element its show me "failed to load the given URL" or "Failed to load response data" .... or

在Inspect元素中,它显示“无法加载给定的URL”或“无法加载响应数据”....或

Failed to load resource: the server responded with a status of 404 (Not Found) jpg

无法加载资源:服务器响应状态为404(未找到)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

我会在这里放一些工具,也许你们会帮我解决这个问题,因为我已经完成了!我无法弄明白

[![enter image description here][1]][1]

[![在此输入图片说明] [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>

---------- my htaccess

----------我的htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [L]
</IfModule>

-------and my uploads.php

-------和我的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
    
}

?>

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 .

我想提一下,我使用dropzonejs,但我认为这并不重要,因为我的图像上传,存储在该文件夹中,但我无法查看它们。我与数据库的关系是正确的。

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
}

Here was the problem , instead of

这是问题,而不是

$targetFile = $targetPath. $name; //5

I had

$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 !**

更明确的是,当我上传图像时,该图像的转换后的名称在我的数据库中运行良好,但它改变了我的上传文件夹中图像的名称...所以它与数据库中的名称与文件夹/不匹配路径...感谢您的支持,当我在编程中成长时,我也会尽力帮助别人!**

2 个解决方案

#1


4  

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.

在你的图像标签中尝试这个src =“在这里使用ci函数作为base_url()/ pathname with img name”,并将你的图像上传到asset / upload。所以可以访问。

#2


3  

When you see that icon, then it usually means it has invalid link to image. Try to right click and open image and check what URL it has. I usually see that it has not the URL I expect to see so it's probably the same for you right now. Accordingly to given url, try to find and fix a mistake in code.

当您看到该图标时,通常意味着它具有无效的图像链接。尝试右键单击并打开图像并检查它具有的URL。我经常看到它没有我希望看到的URL,所以现在可能对你来说也是一样的。根据给定的URL,尝试查找并修复代码中的错误。

#1


4  

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.

在你的图像标签中尝试这个src =“在这里使用ci函数作为base_url()/ pathname with img name”,并将你的图像上传到asset / upload。所以可以访问。

#2


3  

When you see that icon, then it usually means it has invalid link to image. Try to right click and open image and check what URL it has. I usually see that it has not the URL I expect to see so it's probably the same for you right now. Accordingly to given url, try to find and fix a mistake in code.

当您看到该图标时,通常意味着它具有无效的图像链接。尝试右键单击并打开图像并检查它具有的URL。我经常看到它没有我希望看到的URL,所以现在可能对你来说也是一样的。根据给定的URL,尝试查找并修复代码中的错误。