[英]file upload not working php
我得到下面给出的代码的以下错误消息
“警告:mysql_real_escape_string()[function.mysql-real-escape-string]:在网上/home/stthohuu/public_html/forms/upload_newsletter.php中拒绝用户'stthohuu'@'localhost'(使用密码:NO)的访问31“
您能指导我吗..不知道文件上传过程..请分享您的建议
<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td><h4>Please select a file</h4></td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
<a href="newsletter_sec.php">Back</a>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
//$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(stripslashes ($_FILES['userfile']['name'])));
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'stthohuu_batch', 'abc') or die(mysql_error());
$db = mysql_select_db('stthohuu_church', $con);
/* identify the max id in existing data*/
$max_id[0]='';
$sql="SELECT id FROM newsletter WHERE id=(SELECT max(id) FROM newsletter)";
$result = mysql_query($sql);
$max_id = mysql_fetch_array($result);
if ($max_id[0]=='')
{
$max_id[0]=0;
}
$id=0;
$id=$max_id[0]+1;
/* to insert data into newsletter table */
if($db){
$query = "INSERT INTO newsletter (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>
这在本地xampp中工作正常。.但是在Web服务器中不是。
问题出在您的MySQL连接上。 在打开MySQL连接之前,删除mysql_real_escape_string()
。 通常,您的Web服务器将使用与本地xampp帐户不同的用户名和密码 。 改变他们。
另外,最佳实践是不使用mysql_*
函数,而mysqli_*
它们替换为mysqli_*
或PDO
。
您必须使用服务器数据库设置。 您不能将“ localhost”用于服务器数据库。 对于更多服务器,这是它们的数据库IP。 有关更多详细信息,您可以联系服务器管理员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.