我在尝试上传大图片时遇到错误。我是php的新手,请指导我或为我提供更好的编码方式。
我收到了这些错误消息
Warning: mysql_query(): MySQL server has gone away in C:\xampp\htdocs\testing\test.php on line 63
Warning: mysql_query(): Error reading result set's header in C:\xampp\htdocs\testing\test.php on line 63
问题是图像上传。请检查您的数据库
这是我的代码
<?php
//connect to the database//
$con = mysql_connect("localhost","root", "root");
if(!$con)
{
die('Could not connect to the database:' . mysql_error());
echo "ERROR IN CONNECTION";
}
$sel = mysql_select_db("forms1");
if(!$sel)
{
die('Could not connect to the database:' . mysql_error());
echo "ERROR IN CONNECTION";
}
//file properties//
$file = $_FILES['image']['tmp_name'];
$upload=0;
*/for($count = 0; $count < count($_FILES['image']); $count++)
{
if(!empty($_FILES['image']['name'][$count])){
$image_desc[$count] = addslashes($_POST['imageDescription'][$count]);
$image_name[$count] = addslashes($_FILES['image']['name'][$count]); echo '<br \>';
$image_size[$count] = @getimagesize($_FILES['image']['tmp_name'][$count]);
$error[$count] = $_FILES['image']['error'][$count];
if($image_size[$count] === FALSE || ($image_size[$count]) == 0)
echo "That's not an image";
$upload++;
echo $upload;
// Temporary file name stored on the server
$tmpName[$count] = $_FILES['image']['tmp_name'][$count];
// Read the file
$fp[$count] = fopen($tmpName[$count], 'r');
$data[$count] = fread($fp[$count], filesize($tmpName[$count]));
$data[$count] = addslashes($data[$count]);
fclose($fp[$count]);
// Create the query and insert into database.
$results = mysql_query("INSERT INTO files( name, image) VALUES('$image_desc[$count]','$data[$count]')", $con);
if(!$results)
echo "Problem uploding the image. Please check your database";
}
?>
答案 0 :(得分:0)
如果您正在使用本地服务器,则必须更改php.ini文件
以下是步骤: http://alex-lanos.blogspot.com/2012/09/xampp-apache-php-how-to-increase-upload.html
在public_html下创建一个文件并将其命名为php.ini(如果还没有。)将以下内容放入其中: upload_max_filesize = 5M post_max_size = 5M 将5更换为20或更少。如果您要让其他人上传,则尺寸上限会保护您的存储空间免遭滥用/过度使用。 然后,您需要将此行添加到.htaccess文件中:(请将您的cpanel用户名替换为“yourusername”,将命令行末尾添加到php.ini文件位置的命令行末尾 - 另外路径和/ home之间有空格) suPHP_ConfigPath / home / Yourusername / public_html 现在应该增加PHP上传限制。