我在尝试将文件上传到目录时遇到一些错误。这些是错误:
Notice: Undefined index: sPic in C:\wamp\www\uniqueminecraftservers\upload\upload.php on line 8
Notice: Undefined index: sPic in C:\wamp\www\uniqueminecraftservers\upload\upload.php on line 13
Notice: Undefined index: sPic in C:\wamp\www\uniqueminecraftservers\upload\upload.php on line 23
这是我的PHP:
<?php
$name = htmlspecialchars($_POST['sName']);
$ip = htmlspecialchars($_POST['sIp']);
$type = $_POST['sType'];
$port = htmlspecialchars($_POST['sPort']);
$website = htmlspecialchars($_POST['sWeb']);
$video = htmlspecialchars($_POST['sVideo']);
$pic = ($_FILES['sPic']['name']); // line 8
$desc = htmlspecialchars($_POST['sDesc']);
$target = "/uniqueminecraftservers/slist/banners/";
$target = $target . basename( $_FILES['sPic']['name']); // line 13
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("slist") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `postdata` VALUES ('$name', '$ip', '$port', '$type', '$website', '$video', '$desc')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['sPic']['tmp_name'], $target)) // line 23
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
在过去 2 小时的搜索中,我尝试了所有可以在网上找到的东西。我不知道如何解决这个问题。
注意:使用 PHP 5.4.3 在 WAMP 上运行