複数のファイルのアップロードをサポートする画像アップロード機能がありますが、どういうわけか一度にアップロードできるのは最大5つの画像だけです。
一度にアップロードするには、おそらく100枚の写真のように機能する必要があります。
アップロードを処理するPHPファイルは次のとおりです。
session_start();
$path = $_SERVER['DOCUMENT_ROOT'];
// Include the Image class file and database for the database connection
include_once $path . "/includes/db.php";
include_once $path . "/classes/Image.php";
$folderName = $_SESSION['id'];
// Loop through the image array
for ($i = 0; $i < count($_FILES['upload']); $i++) {
// Creating image location information
$fileLink = "upload/$folderName/" . $_FILES['upload']['name'][$i];
$fileType = $_FILES['upload']['type'][$i];
$fileSize = ($_FILES['upload']['type'][$i]) / 1024;
// See if a photo uploads to just upload not to a specific user
$source = "$path/$fileLink";
$insertImageQuery = "INSERT INTO Image (id, image_link, image_type, image_size) VALUES($folderName, '$fileLink', '$fileType', '$fileSize')";
if ((move_uploaded_file($_FILES["upload"]["tmp_name"][$i], $source)) && mysql_query($insertImageQuery)) {
// Create a new image object after a file moves to a location
$curImage = new Image();
$curImage -> scaleFunction($source);
$curImage -> save($source);
}
}
そして、これがImageクラスです。
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require_once ($path . "/includes/constants.php");
class Image {
private $image;
//Private Variable stores image type information
private $image_type;
// It creates a PHP picture "resource" from imagecreate
// calls, and this allows for special function calls
// like imagesy and imagesx.
function load($filename) {
$image_info = getimagesize($filename);
$this -> image_type = $image_info[2];
if ($this -> image_type == IMAGETYPE_JPEG) {
//Create JPEG file from source
$this -> image = imagecreatefromjpeg($filename);
} elseif ($this -> image_type == IMAGETYPE_GIF) {
//Create GIF file from source
$this -> image = imagecreatefromgif($filename);
} elseif ($this -> image_type == IMAGETYPE_PNG) {
//Create PNG file from source
$this -> image = imagecreatefrompng($filename);
}
}
function getWidth() {
// Use a built-in PHP function to get width in pixels
return imagesx($this -> image);
}
function getHeight() {
// Use a built-in PHP function to get height in pixels
return imagesy($this -> image);
}
function resizeToHeight($height) {
$ratio = $height / $this -> getHeight();
$width = $this -> getWidth() * $ratio;
$this -> resize($width, $height);
}
function resizeToWidth($width) {
$ratio = $width / $this -> getWidth();
$height = $this -> getHeight() * $ratio;
$this -> resize($width, $height);
}
// Scale to a particular percentage, for future use
function scale($scale) {
$width = $this -> getWidth() * $scale / 100;
$height = $this -> getheight() * $scale / 100;
$this -> resize($width, $height);
}
function resize($width, $height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this -> image, 0, 0, 0, 0,
$width, $height, $this -> getWidth(),
$this -> getHeight());
$this -> image = $new_image;
}
// Save a picture with a given quality (compression), with
// 100 being the highest quality.
// It is only used for JPEG files because the
function save($filename, $image_type = IMAGETYPE_JPEG, $compression = 100) {
if ($image_type == IMAGETYPE_JPEG) {
imagejpeg($this -> image, $filename, $compression);
} elseif ($image_type == IMAGETYPE_GIF) {
imagegif($this -> image, $filename);
} elseif ($image_type == IMAGETYPE_PNG) {
imagepng($this -> image, $filename);
}
}
function output($image_type = IMAGETYPE_JPEG) {
if ($image_type == IMAGETYPE_JPEG) {
imagejpeg($this -> image);
} elseif ($image_type == IMAGETYPE_GIF) {
imagegif($this -> image);
} elseif ($image_type == IMAGETYPE_PNG) {
imagepng($this -> image);
}
}
function scaleFunction($filename) {
$this -> load($filename);
if ($this -> getHeight() > IMAGE_THRESHOLD) {
$this -> resizeToHeight(IMAGE_THRESHOLD);
}
if ($this -> getWidth() > IMAGE_THRESHOLD) {
$this -> resizeToWidth(IMAGE_THRESHOLD);
}
}
} // End of the image class
?>
さて、これは私がphp.iniに持っているものです
max_execution_time = 120
max_input_time = 120
; Whether to allow HTTP file uploads.
file_uploads = On
; Maximum amount of memory a script may consume (50MB)
memory_limit = 50M
; Maximum size of POST data that PHP will accept.
post_max_size = 30M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
しかし、それでも5つ以上の画像では機能しないようです。私が見つけた記事は、サーバーを再起動すると言っていました。しかし、私のWebサイトはGoDaddyでホストされています。何か案が?
また、これがファイル送信を処理する私のフォームです
<form action="/functions/processor.php" method="post" enctype="multipart/form-data">
<input class="upload choose_file" type="file" name="upload[]" multiple/>
<button class="upload" type="submit">
Upload
</button>
</form>