我有一个网站,我使用PHP和MySQL数据库以及Apache服务器,并且我有一个记录页面,并且它有一个唯一的record_id号,每个记录都有一个唯一的record_id号,我从记录中进入我的画廊页面 页面,并且唯一的record_id编号转到图库页面并抛出URL,在图库页面中,我可以上传图片 到我的服务器上载图像(image_name)和缩略图(image_thumbnail_name)的文件夹,并且唯一的record_id号和标题以及record_date和filter_date以及image_name和thumbnail_name进入我的数据库,在record_images表中有七行,分别是image_id和record_id和record_date和filter_date以及标题和图像和缩略图。当我上传图像时,它通过使用PHP将图像的名称更改为rand号(image_name = rand(1000,9999)。“。”。fileExt;)一切正常,但我需要唯一的record_id号要添加在RAND编号的前面,因此图像的名称将类似于(record_id = 1_5826)和(record_id = 1_thumbnail_5826)或 像(record_id = 2_9631)和(record_id = 1_thumbnail_9631)这样,我就可以按图库页面中的record_id号过滤图像,这样您就只能看到该记录的图像,并且在需要的页面中有所有记录集他们输入ID号,然后我在Dreamweaver中建立了这个网站。
这是用于从记录页面转到图库页面的链接的代码,该页面具有唯一的record_id号,并且其中具有所有其他ID号以及用于向后导航的所有条件和属性。
<a href="/finditlogit/private/sites/logs/artifacts/records/photo_gallery/gallery.php?site_id=<?php echo $row_rssites['site_id']; ?>&block_id=<?php echo $row_rsarchitectural_blocks['block_id']; ?>&log_id=<?php echo $row_rslogs['log_id']; ?>&record_id=<?php echo $row_rsrecords['record_id']; ?>&site_criteria=<?php echo htmlspecialchars ($site_criteria, ENT_QUOTES); ?>&site_attributes=<?php echo htmlspecialchars ($site_attributes, ENT_QUOTES); ?>&block_criteria=<?php echo htmlspecialchars ($block_criteria, ENT_QUOTES); ?>&block_attributes=<?php echo htmlspecialchars ($block_attributes, ENT_QUOTES); ?>&logs_criteria=<?php echo htmlspecialchars ($logs_criteria, ENT_QUOTES); ?>&log_criteria=<?php echo htmlspecialchars ($log_criteria, ENT_QUOTES); ?>&log_attributes=<?php echo htmlspecialchars ($log_attributes, ENT_QUOTES); ?>">Photo Gallery</a>
这是位于图库页面顶部的条件和属性,其中包含用于向后导航的所有条件和属性
<?php require_once('../../../../../../Connections/filidb.php'); ?>
<?php $site_criteria = (isset($_GET['site_criteria']) ? $_GET['site_criteria'] : ''); ?>
<?php $site_attributes = (isset($_GET['site_attributes']) ? $_GET['site_attributes'] : ''); ?>
<?php $block_criteria = (isset($_GET['block_criteria']) ? $_GET['block_criteria'] : ''); ?>
<?php $block_attributes = (isset($_GET['block_attributes']) ? $_GET['block_attributes'] : ''); ?>
<?php $logs_criteria = (isset($_GET['logs_criteria']) ? $_GET['logs_criteria'] : ''); ?>
<?php $log_criteria = (isset($_GET['log_criteria']) ? $_GET['log_criteria'] : ''); ?>
<?php $log_attributes = (isset($_GET['log_attributes']) ? $_GET['log_attributes'] : ''); ?>
<?php session_start(); ?>
这是在图库页面中将图像上传到服务器和数据库的功能,它从计算机上传图像,并在其中添加标题,ID号,标准和属性也随之添加。
<div id="image_upload">
<form action="image_upload_script.php?site_criteria=<?php echo htmlspecialchars ($site_criteria, ENT_QUOTES); ?>
&site_attributes=<?php echo htmlspecialchars ($site_attributes, ENT_QUOTES); ?>&block_criteria=<?php echo htmlspecialchars ($block_criteria, ENT_QUOTES); ?>&block_attributes=<?php echo htmlspecialchars ($block_attributes, ENT_QUOTES); ?>&logs_criteria=<?php echo htmlspecialchars ($logs_criteria, ENT_QUOTES); ?>&log_criteria=<?php echo htmlspecialchars ($log_criteria, ENT_QUOTES); ?>&log_attributes=<?php echo htmlspecialchars ($log_attributes, ENT_QUOTES); ?>" method="POST" enctype="multipart/form-data">
<label>Title</label>
<input type="text" name="title" />
<br>
<label>Select Image To Upload</label>
<br>
<input type="file" name="image_name" />
<br>
<input type="submit" name="submit" value="Upload The Picture">
<input name="site_id" type="hidden" id="site_id" value="<?php echo $row_rssites['site_id']; ?>" />
<input name="block_id" type="hidden" id="block_id" value="<?php echo $row_rsarchitectural_blocks['block_id']; ?>" />
<input name="log_id" type="hidden" id="log_id" value="<?php echo $row_rslogs['log_id']; ?>" />
<input name="record_id" type="hidden" id="record_id" value="<?php echo $row_rsrecords['record_id']; ?>" />
</form>
</div>
这是image_upload_script文件顶部的条件和属性,其中包含用于向后导航的所有条件和属性
<?php require_once('../../../../../../Connections/filidb.php'); ?>
<?php $site_criteria = (isset($_GET['site_criteria']) ? $_GET['site_criteria'] : ''); ?>
<?php $site_attributes = (isset($_GET['site_attributes']) ? $_GET['site_attributes'] : ''); ?>
<?php $block_criteria = (isset($_GET['block_criteria']) ? $_GET['block_criteria'] : ''); ?>
<?php $block_attributes = (isset($_GET['block_attributes']) ? $_GET['block_attributes'] : ''); ?>
<?php $logs_criteria = (isset($_GET['logs_criteria']) ? $_GET['logs_criteria'] : ''); ?>
<?php $log_criteria = (isset($_GET['log_criteria']) ? $_GET['log_criteria'] : ''); ?>
<?php $log_attributes = (isset($_GET['log_attributes']) ? $_GET['log_attributes'] : ''); ?>
<?php session_start(); ?>
这是image_upload_script文件的PHP代码,RAND函数是我试图将record_id号添加到RAND号前面的函数,它从secondary_upload_code.php文件中获取辅助代码都很好,但是添加了记录到RAND函数的record_id号。
<?php
require_once('../../../../../../Connections/filidb.php');
if(isset($_POST['submit']))
{
$site_id = $_POST['site_id'];
$block_id = $_POST['block_id'];
$log_id = $_POST['log_id'];
$record_id = $_POST['record_id'];
$filter_date = date("Y-m-d H:i:s");
$record_date = date("Y-m-d");
$title = $_POST['title'];
$image_name = $_FILES['image_name']['name'];
$thumbnail_image = $_FILES['image_name']['name'];
$fileTmpLoc = $_FILES["image_name"]["tmp_name"];
$fileType = $_FILES["image_name"]["type"];
$fileSize = $_FILES["image_name"]["size"];
$fileErrorMsg = $_FILES["image_name"]["error"];
$image_name = preg_replace('#[^a-z.0-9_]#i', '', $image_name);
$kaboom = explode(".", $image_name);
$fileExt = end($kaboom);
$image_name = rand (1000,9999).".".$fileExt;
$image_name = ("$record_id-$image_name");
// START PHP Image Upload Error Handling -------------------------------
if (!$fileTmpLoc) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button.";
exit();
} else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
exit();
} else if (!preg_match("/.(jpg|jpeg)$/i", $image_name) ) {
// This condition is only if you wish to allow uploading of specific file types
echo "ERROR: Your image was not a .jpg, or .jpeg.";
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
exit();
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again.";
exit();
}
// END PHP Image Upload Error Handling
$insert = "insert into record_images values ('NULL','$record_id','$filter_date','$record_date','$title','$image_name','thumbnail_$image_name')";
if(mysql_query($insert))
{
move_uploaded_file($_FILES['image_name']['tmp_name'], "uploads/$image_name");
echo "<script>alert('Image Has Beent Uploaded To Folder')</script>";
}
else{
echo "<script>alert('Image Does Not Upload To Folder')</script>";
}
// Include the file that houses all of the custom image functions
include_once("secondary_upload_code.php");
// ---------- Start Universal Image Resizing Function
$target_file = "uploads/$image_name";
$resized_file = "uploads/$image_name";
$wmax = 1000;
$hmax = 1000;
universal_image_resizing($target_file, $resized_file, $wmax, $hmax, $fileExt);
// ----------- End Universal Image Resizing Function ----------
// ---------- Include Thumbnail Resizing Function --------
$target_file = "uploads/$image_name";
$resized_file = "uploads/thumbnail_$image_name";
$wmax = 200;
$hmax = 150;
thumbnail_image_resizing($target_file, $resized_file, $wmax, $hmax, $fileExt);
// ----------- End Thumbnail Resizing Function -----------
// ---------- Start Image Watermark Function --------
$target_file = "uploads/$image_name";
$wtrmrk_file = "watermark.png";
$new_file = "uploads/$image_name";
image_watermark($target_file, $wtrmrk_file, $new_file);
// ----------- End Image Watermark Function -----------
}
header ("Location: ../photo_gallery/gallery.php?site_id=$site_id&block_id=$block_id&log_id=$log_id&record_id=$record_id&site_criteria=$site_criteria&site_attributes=$site_attributes&block_criteria=$block_criteria&block_attributes=$block_attributes&logs_criteria=$logs_criteria&log_criteria=$log_criteria&log_attributes=$log_attributes");
exit();
?>
这是secondary_upload_code文件的PHP代码,该代码通过image_upload_script文件中的include secondary_upload_code函数转到image_upload_script文件。
<?php
// ----------------------- Universal Image Resizing FUNCTION -----------------------
function universal_image_resizing($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);{
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
{
imagejpeg($tci, $newcopy, 84);
}
}
// Function for Thumnail resizing image files
function thumbnail_image_resizing($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
{
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
}
// ----------------------- IMAGE WATERMARK FUNCTION -----------------------
function image_watermark($target, $wtrmrk_file, $newcopy) {
$watermark = imagecreatefrompng($wtrmrk_file);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$img = imagecreatefromjpeg($target);
$img_w = imagesx($img);
$img_h = imagesy($img);
$wtrmrk_w = imagesx($watermark);
$wtrmrk_h = imagesy($watermark);
$dst_x = ($img_w / 2) - ($wtrmrk_w / 2); // For centering the watermark on any image
$dst_y = ($img_h / 2) - ($wtrmrk_h / 2); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h);
imagejpeg($img, $newcopy, 100);
imagedestroy($img);
imagedestroy($watermark);
}
?>