Hi. I am a newbie at php an have been scratching my head to work out how to reduce the file size of multiple image uploads through an HTML form. The following HTML form looks like this: -
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><p><strong>Multiple Files Upload</strong></p></td>
</tr>
<tr>
<td>Company
<input type="text" name="company" id="company" size="50">
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
My PHP script so far is successfully creating a new directory, saving images in to that new directory and outputting the results to the user in their browsers for every image which has finished uploading. I have tried some code from this site and others to reduce the file size of each image uploaded but have had no luck to get it to work. My script named "multiple_upload_ac.php" is as follows: -
<?php
//get company name from html form
$dirName = $_POST["company"];
//make directory of the company name
mkdir($dirName, 0777);
//for each image uploaded, move image from temp directory to created company name directory
foreach ($_FILES["ufile"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["ufile"]["tmp_name"][$key];//temporary image uploaded
$name = $_FILES["ufile"]["name"][$key];//prefix file name with "small"
//$smallPic = imagejpeg($name, null, 25)
$path = move_uploaded_file($tmp_name, "$dirName/$name");//move temporary file to named directory. Temporary image automatically destroyed
//for each file, show successful upload, file size and show thumbnail of image
echo "File $name successfully uploaded"."<br>";
echo "Size of file is ". filesize("$dirName/$name"). " bytes". "<br>";
echo "<img src=\"$dirName/$name\" width=\"150\" height=\"150\">". "<br><br>";
}
}
?>
I apologise if this thread has been posted before and appreciate any help, links to tutorials or any other sites that can help me develop my skills further. Thanking everyone in advance.