echo '<img src="'.$row['image_url'].'" class="img-thumbnail">';
这给了我链接
http://localhost/events-uploads/5bc9f6074a2788.39011795.png'
代替
http://localhost/cinematheque-app/events-uploads/5bc9f6074a2788.39011795.png
这就是为什么我上传的图像不会显示...
如何显示正确的网址?
每当我在数据库中保存时,我都会添加“cinematheque-app”关键字,例如,一个 URL 会像这样保存“cinematheque-app/events-uploads/5bc9f6074a2788.39011795.png”
但是每当我使用它将它添加到 img src
echo '<img src="'.$row['image_url'].'" class="img-thumbnail">';
它给了我http://localhost/cinematheque-app/cinematheque-app/events-uploads/5bc9f6074a2788.39011795.png
我是这样保存的...
$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
}
}
}
我是这样理解的...
<?php while ($row = mysqli_fetch_array($events_per_page)) { ?>
<tr class="table table-borderless table-sm text-center">
<td><?php echo $row['title']; ?> </td>
<td><?php echo date("h:ia", strtotime($row['time'])); ?> </td>
<td><?php echo date("M-d-Y", strtotime($row['date'])); ?> </td>
<td><?php echo $row['branch']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['price']; ?></td>
<td>
<?php
// $system_url = "cinematheque-app";
// $removed_front_slash_url = trim( $row['image_url'], "/" );
// $actual_url = trim( $row['image_url'], "." );
echo '<img src="'.$row['image_url'].'" class="img-fluid">';
// echo $row['image_url'];
?>
</td>
查询数据
$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 '<img src="/'.$row['image_url'].'" class="img-fluid">';
$actual_url = "cinematheque-app".trim( $fileDestination, "." );
如何显示正确的网址?
您将正确的 URL 存储在数据库中或查询正确的表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句