Я работаю над своим PHP-скриптом, чтобы открыть мои электронные письма, извлекая данные из базы данных MySQL.Мне нужна помощь с моим кодом, потому что я застрял и не знаю, что делать.Когда я открываю свои электронные письма, я хочу получить данные рядом с alt
, чтобы отправить данные имени файла на /project/u/index
, чтобы они нашли местоположение файла на сервере, а затем отобразили изображения.
Вот что мойизображение будет отображаться как, например:
<img src="/project/u/?id=47394f41507856374130672f6d65534430734f7177513d3d&attid=0.2&msgid=1630808059112201633&view=attachment&display=view" alt="what-is-bootstrap.png" width="452" height="302" class="CToWUd gmail-a6T" tabindex="0">
Вот код index.php:
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
require_once "Mail.php";
require_once('Mail/IMAPv2.php');
$key = "**************";
$email_number = openssl_decrypt(hex2bin($_GET['id']),'AES-128-CBC', $key);
$attach_id = $_GET['attid'];
$attachment_display = $_GET['display'];
$attachments = array();
$body_attachments = array();
$attachment_number = 0;
$inline_number = 0;
$body_number = 0;
if ($attachments >= 1) {
if (($attach_id == 0) or ($attach_id > 0.9)) {
if($attachments[$attach_id])
{
$filename = $attachments[$attach_id]['name'];
$filePath = "attachments/" .$filename;
if($attachment_display == 'download') {
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=".basename($filename));
echo readfile($filePath);
}
else if($attachment_display == 'view') {
$type = 'image/jpeg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
}
}
}
}
if ($body_attachments >= 1) {
if (($attach_id >= 0.1) && ($attach_id <= 0.9)) {
if ($attach_id == '0.1') {
$attach_id = 0;
}
else if ($attach_id == '0.2') {
$attach_id = 1;
}
else if ($attach_id == '0.3') {
$attach_id = 2;
}
else if ($attach_id == '0.4') {
$attach_id = 3;
}
else if ($attach_id == '0.5') {
$attach_id = 4;
}
else if ($attach_id == '0.6') {
$attach_id = 5;
}
else if ($attach_id == '0.7') {
$attach_id = 6;
}
else if ($attach_id == '0.8') {
$attach_id = 7;
}
else if ($attach_id == '0.9') {
$attach_id = 8;
}
else if ($attach_id == '0.10') {
$attach_id = 9;
}
else if ($attach_id == '0.11') {
$attach_id = 10;
}
else if ($attach_id == '0.12') {
$attach_id = 11;
}
else if ($attach_id == '0.13') {
$attach_id = 12;
}
else if ($attach_id == '0.14') {
$attach_id = 13;
}
else if ($attach_id == '0.15') {
$attach_id = 14;
}
else if ($attach_id == '0.16') {
$attach_id = 15;
}
else if ($attach_id == '0.17') {
$attach_id = 16;
}
else if ($attach_id == '0.18') {
$attach_id = 17;
}
else if ($attach_id == '0.19') {
$attach_id = 18;
}
else if ($attach_id == '0.20') {
$attach_id = 19;
}
else if ($attach_id == '0.21') {
$attach_id = 20;
}
else if ($attach_id == '0.22') {
$attach_id = 21;
}
else if ($attach_id == '0.23') {
$attach_id = 22;
}
else if ($attach_id == '0.24') {
$attach_id = 23;
}
else if ($attach_id == '0.25') {
$attach_id = 24;
}
else if ($attach_id == '0.26') {
$attach_id = 25;
}
else if ($attach_id == '0.27') {
$attach_id = 26;
}
else if ($attach_id == '0.28') {
$attach_id = 27;
}
else if ($attach_id == '0.29') {
$attach_id = 28;
}
else if ($attach_id == '0.30') {
$attach_id = 29;
}
if(!$body_attachments[$attach_id]) {
$attach_id++;
}
if($body_attachments[$attach_id])
{
$filename = $body_attachments[$attach_id]['name'];
$filePath = "attachments/" .$filename;
if($attachment_display == 'download') {
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=".basename($filename));
echo readfile($filePath);
}
else if($attachment_display == 'view') {
$type = 'image/jpeg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
}
}
}
}
?>
Вот что я использую, чтобы открыть свои электронные письма, используя базу данных:
<?php
// Initialize the session
session_start();
//Connect to the database
include('config.php');
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
header("location: login.php");
exit;
}
else
{
$id = $_POST['email_number'];
$mailfolder = $_POST['mailfolder'];
$readMail = 'read';
$mailbox = $link->prepare("UPDATE " . $mailfolder . " SET readtype = ? WHERE id = ?");
$mailbox->execute([$readMail, $id]);
// set the resulting array to associative
$row = $mailbox->fetch(PDO::FETCH_ASSOC);
if($mailbox->rowCount() == 1)
{
$results = array();
$mailbox_from = $row['from_email'];
$mailbox_from_ = explode('<', $mailbox_from);
$mailbox_from_name = $mailbox_from_[0];
$mailbox_from_email = '<' . $mailbox_from_[1];
$mailbox_from_email = htmlspecialchars($mailbox_from_email);
$mailbox_to = $row['to_email'];
$mailbox_to_name = $mailbox_to;
$mailbox_subject = quoted_printable_decode($row['subject']);
$mailbox_fulldate = $row['received_date'];
$mailbox_date = convDate($mailbox_fulldate);
$mailbox_message = $row['message'];
$mailbox_attachment = $row['attachments'];
$mailbox_folder = $_POST['folder'];
$total = $_POST['total'];
$email_encrypt = $row['encryption'];
$send_to = $mailbox_from_email;
$results['mailbox_from'] = $mailbox_from;
$results['mailbox_from_'] = $mailbox_from_;
$results['mailbox_from_name'] = $mailbox_from_name;
$results['mailbox_from_email'] = $mailbox_from_email;
$results['mailbox_to'] = htmlspecialchars($mailbox_to);
$results['mailbox_subject'] = $mailbox_subject;
$results['mailbox_fulldate'] = $mailbox_fulldate;
$results['mailbox_date'] = $mailbox_date;
$results['mailbox_message'] = $mailbox_message;
$results['mailbox_attachment'] = $mailbox_attachment;
$results['mailbox_folder'] = $mailbox_folder;
$results['total'] = $total;
$results['email_encrypt'] = $email_encrypt;
$results['send_to'] = $send_to;
$results['time_elapsed'] = $time_elapsed;
$results['mailed_by_date'] = $mailed_by_date;
$results['mailed_by'] = $mailed_by;
$results['mailbox_to_name'] = $mailbox_to_name;
$results['attach_test'] = $attach_test;
$data = array("start"=>$start_idx,"total"=>$total,"encryption"=>$email_encrypt);
$response = array("data"=>$data,"html"=>$html, "total_inbox"=>$total_inbox_unread, "total_draft"=>$total_draft_unread, "total_spam"=>$total_spam_unread, "emailBodyMessage"=>$results, "emailHeader"=>$header);
echo json_encode($response);
}
}
//Close connection
$mailbox = null;
?>
Я хочу получить данные имени файла рядом с alt
, чтобы я мог отправить данные в /project/u/index.php для отображения изображения.