我制作了这个PHP脚本来添加这样的新闻
$addnewstable .="<table>
<tr>
<td>
<div id=\"boxdiv\">
<form method=\"GET\" name=\"formone\" enctype=\"multipart/form-data\">
<textarea name=\"news_textarea\" placeholder=\"Add News Here\"></textarea>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"8388608\"/>
</td>
</tr>
<tr>
<td>
<input type=\"text\" name=\"hyperlink\" placeholder=\"Add Hyperlink of news Here\"/>
</td>
</tr>
<tr>
<td>
<textarea name=\"statement_textarea\" placeholder=\"Add news statement Here\" ></textarea>
</td>
</tr>
<tr>
<td>
<input type=\"file\" name=\"uploadimage\" id=\"fileupload\">
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><input type=\"Submit\" name=\"Submit\" value=\"Add News\"/>
</form></div>
</td>
</tr></table>";
我的$ _FILES无效
我的PHP代码是
if ($_REQUEST['Submit'] == 'Add News' && isset($_REQUEST['news_textarea']) && isset($_REQUEST['hyperlink']) && isset($_REQUEST['statement_textarea']) )
{
$news = mysql_real_escape_string($_REQUEST['news_textarea']);
$hyperlink = mysql_real_escape_string($_REQUEST['hyperlink']);
$statement = mysql_real_escape_string($_REQUEST['statement_textarea']);
$filename = $_FILES['uploadimage']['name'];
$filesize = $_FILES["uploadimage"]["size"];
$filetype = $_FILES["uploadimage"]["type"];
$namelength = strlen($filename);
$imageData = @getimagesize($_FILES["uploadimage"]["tmp_name"]);
$max_filesize =mysql_real_escape_string($_REQUEST['MAX_FILE_SIZE']) ;
$errors = array();
$timeSt = md5(time());
$time = date('Y-m-d H:i:s');
$info = pathinfo($filename);
$name = $info['filename'];
$format = $info['extension'];
$imagerealname = basename($name);
$imgpath ="../img/news/".$imagerealname."_".$timeSt."_".$format;
$errorsize = "<span >Error :-</span> Exceeding Image size Upload ";
$errorupload = "<span >Error :-</span> Not an Image Uploading Failed";
echo $filename.$imagerealname;
echo "<br/>".$imgpath.'<br/><br/>';
if(filesize($_FILES["uploadimage"]["tmp_name"]) > $max_filesize) {
$errors[] = $errorsize;
}
if($imageData === FALSE || !($imageData[2] == IMAGETYPE_GIF || $imageData[2] == IMAGETYPE_JPEG || $imageData[2] == IMAGETYPE_PNG)) {
$errors[] = $errorupload;
}
// If array ERRORS is empty than insert data in form
if (empty($errors)) {
if (move_uploaded_file($_FILES["uploadimage"]["tmp_name"], $imgpath)) {
$request=" INSERT INTO `photoshoot`.`pages_position_id` (`news` ,`hyperlink` ,`statement` ,`imgpath`) VALUES ( '".$news."','".$hyperlink."','".$statement."', '".$imgpath."')";
echo $request;
$query = mysql_query($request);
if($query) {
echo "<script type=\"text/javascript\">window.location.href = 'http://localhost/ourwork/photoshoot/CMS/samples/sample_new.php'; </script>";
}
}
}
}
我的$ _FILES不工作我无法找出原因:(需要你的意见
答案 0 :(得分:2)
默认情况下,method
代码的<form>
为GET
。您需要将其明确指定为POST
。使用此:
<form method=\"\" name=\"formone\" enctype=\"multipart/form-data\" method=\"POST\">