其他的都能上传,就是图片上传不上去(数据库里能看到itemId等等但是图片大小是0),网上查了些资料,貌似上传图片是把图片保存在文件夹里面,phpmyadmin上面是保存的地址?
以下是code
<?phpinclude("connect.php");//connect.php连接到phpmyadmin$userId = $_POST['user'];
$title = $_POST['title'];
$category = $_POST['category'];
$description = $_POST['description'];
$price = $_POST['price'];
$postage = $_POST['postage'];
$type = $_POST['type'];
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$hour = $_POST['hour'];
$mins = $_POST['mins'];
$secs = $_POST['secs']; $query = "INSERT INTO iBayItems (userId, title, category, description, price, postage, finish) VALUES ('$userId', '$title', '$category', '$description', '$price', '$postage - $type', '$year-$month-$day $hour:$mins:$secs')";$query2 = "SELECT itemId FROM iBayItems WHERE userId='$userId' && title='$title'&& category='$category' && description='$description' && price='$price' && postage='$postage - $type' && finish='$year-$month-$day $hour:$mins:$secs'";$data = mysql_query($query);
$data2 = mysql_query($query2);$row = mysql_fetch_array($data2); $item = $row['itemId'];if(isset($_POST['image'])) {$fileName = $_FILES["image"]['name'];
$tmpName = $_FILES["image"]['tmp_name'];
$fileSize = $_FILES["image"]['size'];
$fileType = $_FILES["image"]['type'];
$query3 = "INSERT INTO iBayImages (image, mimeType, imageSize, itemId) VALUES ('$fileName', '$fileType', '$fileSize', '$item')";
echo $query3;
$data3 = mysql_query($query3);
}echo "<p>You have uploaded the following item:<p>";echo "<br />"; echo "<p>Title: $title</p>";
echo "<p>Category: $category</p>";
echo "<p>Price: £$price</p>";
echo "<p>Postage: $postage - $type</p>";
echo "<p>Finish: $day-$month-$year $hour:$mins:$secs</p>";?>
</h4>
<h4><a href="login.htm">View all of my items</a></h4>
</body>
</html>
有谁知道怎么上传的code吗,或者给点资料也行
以下是code
<?phpinclude("connect.php");//connect.php连接到phpmyadmin$userId = $_POST['user'];
$title = $_POST['title'];
$category = $_POST['category'];
$description = $_POST['description'];
$price = $_POST['price'];
$postage = $_POST['postage'];
$type = $_POST['type'];
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$hour = $_POST['hour'];
$mins = $_POST['mins'];
$secs = $_POST['secs']; $query = "INSERT INTO iBayItems (userId, title, category, description, price, postage, finish) VALUES ('$userId', '$title', '$category', '$description', '$price', '$postage - $type', '$year-$month-$day $hour:$mins:$secs')";$query2 = "SELECT itemId FROM iBayItems WHERE userId='$userId' && title='$title'&& category='$category' && description='$description' && price='$price' && postage='$postage - $type' && finish='$year-$month-$day $hour:$mins:$secs'";$data = mysql_query($query);
$data2 = mysql_query($query2);$row = mysql_fetch_array($data2); $item = $row['itemId'];if(isset($_POST['image'])) {$fileName = $_FILES["image"]['name'];
$tmpName = $_FILES["image"]['tmp_name'];
$fileSize = $_FILES["image"]['size'];
$fileType = $_FILES["image"]['type'];
$query3 = "INSERT INTO iBayImages (image, mimeType, imageSize, itemId) VALUES ('$fileName', '$fileType', '$fileSize', '$item')";
echo $query3;
$data3 = mysql_query($query3);
}echo "<p>You have uploaded the following item:<p>";echo "<br />"; echo "<p>Title: $title</p>";
echo "<p>Category: $category</p>";
echo "<p>Price: £$price</p>";
echo "<p>Postage: $postage - $type</p>";
echo "<p>Finish: $day-$month-$year $hour:$mins:$secs</p>";?>
</h4>
<h4><a href="login.htm">View all of my items</a></h4>
</body>
</html>
有谁知道怎么上传的code吗,或者给点资料也行
不用说你,就算是高手高手高高手都没办法.
建议你好好看书,从基础开始学.
2个文件,前台文件user.html,处理文件deal.php
1前台文件user:
<html><body>
<p>请上传你的树文件</p>
<form action="deal.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"/>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body></html>
2后台处理文件deal.php
<?php
echo $_FILES["file"]["type"]."<br />";
if( $_FILES["file"]["type"] == "text/plain")
//只接受文本上传出于安全,还可以是'image/jpeg','image/png','image/gif', //'image/bmp','image/x-png'等类型
{
$uploaddir="/var/www/upload/";//设置文件上传目录windows下可以是"c:/upload/"
////////////////////////////////文件目录必须开放对所有人可读写!!
if($_FILES["file"]["error"]>0)
{
echo "Error:".$_FILES["file"]["error"]."<br/>";
}
else
{
if(file_exists($uploaddir.$_FILES["file"]["name"]))
{echo $_FILES["file"]["name"]." is already exists! ";}
else
{
$uploaderfile=$uploaddir.$_FILES["file"]["name"];
if(move_uploaded_file($_FILES["file"]["tmp_name"],$uploaderfile))
{
echo "stroed in:".$uploaddir.$_FILES["file"]["name"]."<br />";
}
else
{echo "upload failed!"."<br />";
}
}
}
else
{echo "file type error!"."<br />";}
?>
以上在 linux下apache+php可以运行,注意上传目录的权限对所有人开放.
祝好运!
index.php文件:
<body>
<form enctype="multipart/form-data" action="upload.php" method="post" name="form">
<p>
<input type="file" name="file">
<input type="submit" name="Submit" value="上传">
</p>
</form>
</body>
upload.php文件如下:
<?php
session_start();$id=mysql_connect('localhost','root','');
mysql_select_db('upload',$id);if(isset($_POST['Submit']) ){
$file_name=$_FILES['file']['name'];
$path = './images/'.$_FILES['file']['name'];
date_default_timezone_set('PRC');
$date = date('Y-m-d H:i:s');
if (move_uploaded_file($_FILES['file']['tmp_name'],$path)) {
$query="insert into pic (id,name,path,date) values('','$file_name','$path','$date')";
$result=mysql_query($query);
}
if($result==true){
echo 'Upload successful!!';
echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php \">";
}else{
echo "Upload Failed!!";
echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php \">";
}
}
?>