My website allows the user to upload an album of images to their profile and share them with others on the site.
The script is broken down into two files:
uploadAnAlbum.php
<?php
session_start();
set_time_limit (0);
$email = $_SESSION["accountEmailAddress"];
$accountDir = str_replace("@", "at", $email);
$accountDir = str_replace(".", "dot", $accountDir);
$folderStructure = "./albums/" . $accountDir . "/" . round(microtime(true));
$folderCreation = mkdir($folderStructure, 0755, true);
$host = "localhost";
$username = "XXXXXX";
$password = "XXXXXX";
$database = "XXXXXX";
$connection = mysql_connect($host, $username, $password) or die(mysql_error() . "connection");
mysql_select_db($database) or die(mysql_error() . "database");
$tableName = $accountDir . round(microtime(true));
$createTable = "CREATE TABLE `" . $tableName . "` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`path` TEXT DEFAULT NULL
) ENGINE = MYISAM;";
$createTableResult = mysql_query($createTable) or die(mysql_error() . "sql<br>" . mysql_errno());
echo "<h1>" . count($_FILES['files']['name']) . "</h1>";
$count = 0;
foreach ($_FILES['files']['name'] as $i => $name) {
if (strlen($_FILES['files']['name'][$i]) > 1 && getimagesize($_FILES['files']['tmp_name'][$i]) !== false) {
$extensionArray = explode(".", $_FILES["files"]["name"][$i]);
$extension = end($extensionArray);
$newfilename = $count . '.' . $extension;
if (move_uploaded_file($_FILES['files']['tmp_name'][$i], $folderStructure . "/" . $newfilename)) {
$photoPath = $folderStructure . "/" . $newfilename;
$sql = "INSERT INTO `" . $tableName . "` (path) VALUES ('$photoPath')";
$result = mysql_query($sql) or die(mysql_error() . "hhh");
$count = $count + 1;
}//MOVES INDEX TO FOLDER; UPDATES $COUNT
} else { //CHECK IF FILE IS REAL BEFORE MOVING INTO DIRECTORY
continue;
}
echo $count;
}//END FOREACH ITERATING ARRAY OF UPLOADED FILES
$name = $_REQUEST['albumName'];
$author = $_SESSION['accountEmailAddress'];
$date = date("y/m/d");
$teams = $_REQUEST['teamOne'] . "," . $_REQUEST['teamTwo'];
if($_SESSION['accountStatus'] == "pro"){
$proOrNo = "pro";
} else {
$proOrNo = "no";
}
$sport = $_REQUEST['sport'];
$path = $tableName;
$views = 0;
$host = "XXXXXX";
$username = "XXXXXX";
$password = "XXXXXX";
$database = "XXXXXX";
$connection = mysql_connect($host, $username, $password);
mysql_select_db($database);
$sql = "INSERT INTO albums (name, author, dateUploaded, teams, sport, views, path, proOrNo) VALUES ('$name', '$author', '$date', '$teams', '$sport', '$views', '$path', '$proOrNo')";
$result = mysql_query($sql) or die(mysql_error() . "nn");
header("Location: myAccount.php");
?>
chooseFile.php (HTML form)
<form action="uploadAlbum.php" method="post" enctype="multipart/form-data">
Choose album:<br>
<input type="file" name="files[]" id="files" multiple="" directory="" webkitdirectory="" mozdirectory=""><br>
Name:<input type="text" name="albumName" style="width:100%;"/><br><br>
Sport:
<select name="sport">
<option name="nothing">Select</option>
<option name="football">Football</option>
<option name="crossCountry">Cross country</option>
<option name="fieldHockey">Field hockey</option>
<option name="golf">Golf</option>
<option name="gymnastics">Gymnastics</option>
<option name="soccer">Soccer</option>
<option name="softball">Softball</option>
<option name="tennis">Tennnis</option>
<option name="volleyball">Volleyball</option>
<option name="basketball">Basketball</option>
<option name="hockey">Hockey</option>
<option name="swimming">Swimming</option>
<option name="wrestling">Wrestling</option>
<option name="baseball">Baseball</option>
<option name="lacrosse">Lacrosse</option>
<option name="track">Track and field</option>
</select><br><br>
Teams competing: <br>
<select name="teamOne">
<option value="empty">Choose school #1</option>
<!-- Lots and lots of options for school districts. I took them out to eliminated needless scrolling while you are reading this -->
</select>
<select name="teamTwo">
<option value="empty">Choose school #2</option>
<!-- Lots and lots of options for school districts. I took them out to eliminated needless scrolling while you are reading this -->
</select>
<br>
<input type="submit" name="submit" value="Upload album" />
</form>
For some reason, only 20 indexes of the $_FILES array are passing from the html input form to the php upload script. Before any code manipulating the photos on uploadAnAlbum.php is run, I can see the $_FILES array (passed from chooseFile.php) is limited to the first 20 photos in the user's uploaded directory.
I have spoke on the phone with my web hosting company for three hours and configured the php.ini to be accepting of very large files no matter the upload time.
I have still gotten no where.
If you could take a look at this code to see if anything jumps out at you I would greatly appreciate it.