0

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

?>
4

1 回答 1

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 文件中:(请将“yourusername”替换为您的 cpanel 用户名,并将文件夹添加到 php.ini 文件所在位置的命令行末尾 - 另外path 和 /home 之间有一个空格) suPHP_ConfigPath /home/Yourusername/public_html 现在应该增加您的 PHP 上传限制。

于 2013-10-23T06:36:37.973 回答