在php sql代码中包含缩略图上传
我有一个用php编写的上传到mysql的脚本,它非常适合一个酒店网站——插入所有相关字段和主图像 但是,问题是,该图像用于幻灯片放映,该幻灯片将缩略图标识为xxxxxt.png,例如,主图像为xxxxx.png 我的php代码是:在php sql代码中包含缩略图上传,php,mysql,thumbnails,image-uploading,Php,Mysql,Thumbnails,Image Uploading,我有一个用php编写的上传到mysql的脚本,它非常适合一个酒店网站——插入所有相关字段和主图像 但是,问题是,该图像用于幻灯片放映,该幻灯片将缩略图标识为xxxxxt.png,例如,主图像为xxxxx.png 我的php代码是: <?php include 'dbc.php'; page_protect(); if(!checkAdmin()) {header("Location: login.php"); exit(); } $host = $_SERVER['HTTP_HOST
<?php include 'dbc.php'; page_protect();
if(!checkAdmin()) {header("Location: login.php");
exit();
}
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path = rtrim($login_path, '/\\');
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}
foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}
$uniqid = md5(uniqid(mt_rand()));
?>
<?php
if($_FILES['photo']) //check if we uploading a file
{
$target = "images/properties/";
$target = $target . basename( $_FILES['photo']['name']);
$title = mysql_real_escape_string($_POST['title']);
$desc = mysql_real_escape_string($_POST['desc']);
$extra = mysql_real_escape_string($_POST['extra']);
$postcode = mysql_real_escape_string($_POST['postcode']);
$price = mysql_real_escape_string($_POST['price']);
$pandp = mysql_real_escape_string($_POST['pandp']);
$pic = "images/properties/" .(mysql_real_escape_string($_FILES['photo']['name']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
mysql_query("INSERT INTO `furnishings` (`title`, `postcode`, `desc`, `extra`, `productcode`, `price`, `status`, `pandp`, `photo`) VALUES ('$title', '$postcode', '$desc', '$extra', '" . $uniqid . "', '$price', 'tolet.png', '$pandp', '$pic' )") ;
echo "The property has been added to the lettings portfolio";
}
else
{
echo "Error uploading new property - please ensure all the fields are correctly entered and the file is an image";
}
}
?>
如果您的图像文件被成功移动到位,我会采取以下策略:在数据库表中创建列是上载的
,是创建的
,是创建的
。成功上传和移动后,设置第一个
然后运行cron或其他后台系统,从上传的图像生成“main”和“thumb”视图(请记住,对于普通屏幕大小的图片,上传的图像可能太大)。成功生成这些图像后,相关列可以设置为“完成”,并且该行将保持非活动状态,直到发生这种情况
顺便说一句,这种方法的可扩展性要大得多,因为它不会因为昂贵的图像处理而阻塞您的web请求。我不明白。您是在尝试使用与全尺寸图像和缩略图相同的图像,还是将图像大小调整为缩略图大小?非常简单-编写代码告诉PHP将文件移动到何处。你已经有了基本的move_uploaded_file()
调用-PHP将移动的文件放在哪里完全取决于你。我正在尝试将两个版本的图像上载到服务器-一个名为image.png,另一个名为imaget.png…如果我不清楚,很抱歉,为什么这个问题会得到否定分数!?它遵循所有的指导原则,我只是在得到一些帮助之后!image.png
和image.png
会是同名的图像吗?
<form enctype="multipart/form-data" action="addlet.php" method="POST">
<table width="600px" border="2" cellpadding="5"class="myaccount">
<tr>
<td width="135">Title: </td>
<td width="427"><input name="title" type="text" size="40"/></td>
</tr>
<tr>
<td>Description: </td>
<td><textarea name = "desc" rows="3" cols="40"></textarea></td>
</tr>
<tr>
<td>Property Features: </td>
<td><textarea name = "extra" rows="3" cols="40"></textarea></td>
</tr>
<tr>
<td>Postcode: </td>
<td><input name = "postcode" type="text" size="40" /></td>
</tr>
<tr>
<td>Price per week (£): </td>
<td><input name = "price" type="text" size="40" /></td>
</tr>
<tr>
<td>Furnished/Unfurnished: </td>
<td><input name = "pandp" type="text" size="40" /></td>
</tr>
<tr>
<td>Main Image: </td>
<td><input type="file" name="photo" class="forms" /></td>
</tr> </table></p>
<p> <input type="submit" class="CMSbutton" value="Add" /></p>
</form>