【发布时间】:2014-10-22 13:39:49
【问题描述】:
我需要帮助,我想创建一个可以上传两张图片的表单,一张用于缩略图,一张用于主图。它们都应该保存在不同的文件夹中,但保存在一个数据库表中。谢谢,这是我所做的,但问题是 1. 图片没有保存在数据库中
<?php
require_once('includes/rypecms.php');
error_reporting(0);
if($_POST['submit'])
{
$lname=basename($_FILES['file_upload']['name']);
$ltname=$_FILES['file_upload']['tmp_name'];
$tname=basename($_FILES['file_upload']['tname']);
$ttname=$_FILES['file_upload']['tmp_name'];
$imagename = $_POST['imagename'];
$content = $_POST['content'];
$links = $_POST['links'];
$dir='image';
$dir2='thumb';
if(move_uploaded_file($ltname,$dir."/".$lname)){
if(move_uploaded_file($ttname,$dir2."/".$tname)){
{
mysql_select_db($database_rypecms, $rypecms);
$qur="INSERT INTO portweb (id, name, tname, imagename, content, links, pathl, patht) VALUES(' ', '$lname', '$tname', '$imagename', '$content', '$links', 'image/$lname' , 'thumb/$tname' )";
$res=mysql_query($qur , $rypecms);
echo 'files upload success';
}
}
}
}
?>
here is the form. two file upload buttons.one for thumbnail and the other for the main image
<html>
<head>
<title>upload pictures portfolio web</title>
</head>
<body>
<a href="portweb.php">Back</a>
<br />
<form action="addportweb.php" method="post" enctype="multipart/form-data">
<label>Main image:</label><input type="file" name="file_upload" /><br />
<label>Thumbnail:</label><input type="file" name="file_upload" /><br />
<label>Name:</label> <input type="text" name="imagename" class="text_input" maxlength="100" /><br />
<label>Description:</label>
<textarea name="content" style="width: 300px; height:80px; padding: 5px; resize:none;" ></textarea>
<br />
<label>Link:</label> <textarea name="links" style="width: 100px; height:50px; padding: 5px; resize:none;" ></textarea><br />
<input type="submit" name="submit" value="upload" />
</form>
</body>
</html>
【问题讨论】:
-
向我们展示您的表单 HTML 代码。
-
拜托,don't use
mysql_*functions,它们不再维护,而是officially deprecated。请改为了解 prepared statements,并使用 PDO 或 MySQLi。 This article 将帮助您做出决定。 -
为每个文件输入选择唯一的名称并相应地处理。