我在尝试上传大图时出错。我是 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";
}
?>