我在上传大小为 1.5MB 的图像时收到警告,并且图像没有存储到数据库中,它适用于小于 1MB 的图像。
请帮忙,因为我在这些警告中坚持了几天。
这是我的代码:
<?php
print_r($_FILES);
//connect to the database//
try {
$pdo = new PDO('mysql:host=localhost;dbname=forms1', 'root', 'root',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$file = $_FILES['image']['tmp_name'];
$upload=0;
for($count = 0; $count < count($_FILES['image']); $count++)
{
if(!empty($_FILES['image']['name'][$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.
$stmt = $pdo->prepare('INSERT INTO files (name,image) VALUES (:name,:image)');
$stmt->execute(array('name' => $image_name[$count],'image' => $data[$count]));
if(!$stmt)
echo "Problem uploding the image. Please check your database";
}
}
} catch (PDOException $e) {
print "Error!: " . $e->getMessage();
die();
}
?>
这些是我得到的警告:
Warning: PDOStatement::execute(): MySQL server has gone away in C:\xampp\htdocs\testing\test.php on line 56
Warning: PDOStatement::execute(): Error reading result set's header in C:\xampp\htdocs\testing\test.php on line 56
此行的警告点:
$stmt->execute(array('name' => $image_name[$count],'image' => $data[$count]));