您好,我想上传一些图片到我的服务器。当我没有将带有 ajax.load 的页面加载到另一个页面时,它可以工作。因此,通过直接链接它可以正常工作。但我想点击一个链接,打开上传表单并上传图片(全部在一个窗口中)。这是因为页面在上传之前刷新还是另一个问题?不知道如何解决这个问题。
代码:
<?php
include('includes/connect.php');
if(isset($_POST['uploadImg'])){
$extension = end(explode(".", $_FILES["file"]["name"]));
$name = $_FILES["file"]["name"];
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
mysql_query("INSERT INTO images (itemID,imgPath,imgName,imgExtension,imgAlt) VALUES (".$_POST['itemNumber'].",'upload','".$name."','".$extension."','".$name."')")or die('kan niet uploaden'.mysql_error());
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Uw afbeelding is toegevoegd aan item".$_POST['itemNumber'];
echo "<a id='uploadNew' href='#'>Nog een item uploaden</a>";
}
mysql_query("INSERT INTO images (itemID,imgPath,imgName,imgExtension,imgAlt) VALUES (".$_POST['itemNumber'].",'upload','".$name."','".$extension."','".$name."')")or die('kan niet uploaden'.mysql_error());
}
?>
<form method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
Toevoegen aan:
<select name="itemNumber">
<?
$result = mysql_query("SELECT * FROM items");
while($row = mysql_fetch_array($result))
{
echo '<option name="itemVal" value="'.$row['itemID'].'">'.$row['itemTitle'].'</option>';
echo "<br />";
}
?>
</select>
<input type="submit" name="uploadImg" value="submit" />
</form>