php img src提供了错误的url

php img src提供了错误的url,php,html,Php,Html,而不是 http://localhost/events-uploads/5bc9f6074a2788.39011795.png' 这就是为什么我上传的图片不会显示 如何显示正确的url 每当我在数据库中保存时,我都会添加'cinematheque app'关键字,例如,URL会像这样保存“cinematheque app/events uploads/5bc9f6074a2788.39011795.png” 但是每当我用这个将它添加到img src时 http://localhost/cine

而不是

http://localhost/events-uploads/5bc9f6074a2788.39011795.png'
这就是为什么我上传的图片不会显示

如何显示正确的url

每当我在数据库中保存时,我都会添加'cinematheque app'关键字,例如,URL会像这样保存“cinematheque app/events uploads/5bc9f6074a2788.39011795.png”

但是每当我用这个将它添加到img src时

http://localhost/cinematheque-app/events-uploads/5bc9f6074a2788.39011795.png
我是这样得到的

echo '<img src="'.$row['image_url'].'" class="img-thumbnail">';
$file =$_FILES['image_url'];
$fileName = $_FILES['image_url']['name'];
$fileTmpName = $_FILES['image_url']['tmp_name'];
$fileSize = $_FILES['image_url']['size'];
$fileError = $_FILES['image_url']['error'];
$fileType = $_FILES['image_url']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));



if (in_array($fileActualExt, $allowed)){
    if ($fileError === 0){
        if($fileSize > 20000) {
            $fileNameNew = uniqid('', true).".".$fileActualExt;
            $fileDestination = '../events-uploads/'.$fileNameNew;
            $actual_url = "cinematheque-app".trim( $fileDestination, "." );

            move_uploaded_file($fileTmpName, $fileDestination);

            $mysqli->query("INSERT INTO events (title, time, date, branch, description, price, status, created_at, image_url) 
            VALUES ('$title', '$time', '$date', '$branch', '$description', '$price', '$status', '$created_at', '$actual_url')") or die($mysqli->error);

        header("Location: ../manage-events.php?added=success"); 
        }
        else {
            //File is too big
        }
    }else{
        //There is some error
    }
}       
}

这就是我的转变

$total_events = $mysqli->query("SELECT * from events") or die($mysqli->error);
我知道了

我曾经

$number_of_results = $total_events->num_rows;
$results_per_page  = 4;
$number_of_pages   = ceil($number_of_results / $results_per_page);

$this_page_first_result = ($page-1)*$results_per_page;
$sql="SELECT * FROM events ORDER BY created_at DESC LIMIT " .$this_page_first_result . "," .  $results_per_page;
$events_per_page = $mysqli->query($sql) or die($mysqli->error);
echo';
$actual_url=“cinematheque app”.trim($fileDestination,”);
如何显示正确的url


您可以在数据库中存储正确的URL或查询正确的表。

尝试添加包含您的文件的文件夹的名称,如下所示:

echo '<img src="/'.$row['image_url'].'" class="img-fluid">'; 
$actual_url = "cinematheque-app".trim( $fileDestination, "." );
echo';

在数据库中,只保存不带路径或文件夹名称的文件名,并在html中添加文件夹名称。

OK。你有问题吗?看起来有人在数据库中存储了错误的内容。因为您的
$row['image\u url']
仅包含“否,实际上它包含事件上载/5bc9f6074a2788.39011795.png,如何获取正确的url?不,它不包含。除非你查询了错误的表。你找到了吗?这不是被动攻击吗?不,这是直接的@NiMusco,根据我们目前所知。他应该能够从数据库中获取整个路径。这成功了!我只是将文件名“5bc9f6074a2788.39011795.png”保存在echo“”中;但这并不能解释为什么不能从数据库中获取完整路径
$number_of_results = $total_events->num_rows;
$results_per_page  = 4;
$number_of_pages   = ceil($number_of_results / $results_per_page);

$this_page_first_result = ($page-1)*$results_per_page;
$sql="SELECT * FROM events ORDER BY created_at DESC LIMIT " .$this_page_first_result . "," .  $results_per_page;
$events_per_page = $mysqli->query($sql) or die($mysqli->error);
echo '<img src="/'.$row['image_url'].'" class="img-fluid">'; 
$actual_url = "cinematheque-app".trim( $fileDestination, "." );
echo '<img src="cinematheque-app/'.$row['image_url'].'" class="img-thumbnail">';