Forum Moderators: coopster

Message Too Old, No Replies

urgent problem for multiple image upload and resize

i am stuck in a project, pls help

         

Sobriquet

5:47 am on Jul 21, 2005 (gmt 0)

10+ Year Member



I am using the following code for uploading multiple files ( images ) on the server. I need to resize each of them during the upload process. Can anyone help me with the present script pls.
Thanks a lot.
--------------

Form Input Code:

<form action="picpost.php" method="post" enctype="multipart/form-data" name="stage4" id="stage4">
<table width="700" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF">
<tr bordercolor="#C0C0C0" bgcolor="#EEEEEE">
<td valign="top"><div align="center">
<p>
<?php
$numoffile = 1+$_POST['expics'];
for($i=0;$i<$numoffile;$i++) {
print "<input type='file' name='myfiles[]' size='30'><br>";
}
?>
</p>

<input type="submit" name="Submit" value="Upload" />
</form>
---------------------------

uploading script ( this is where i need help to resize the picturs to 300 pixels height )

<?php
$listfolderid=$row_rsmem['mem_id'].time();
$numoffile = 1 + $_POST['expics'];
$mypath="/serversomepath/"."/".$listfolderid."/";
mkdir($mypath, 0777);
$file_dir = $mypath;
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i],$newfile);
$j++;
}
}
}
if (isset($j)&&$j>0) print "<br><b>Your file(s) has been uploaded.</b><br>";

?>
-----------------------

Also, in the same script, how do i block non image files? ( i am not a fully grown php guy - so need help )

coopster

12:36 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The PHP Image [php.net] functions page is a good start. There is an imagecopyresized [php.net] function that allows you to copy and resize part of an image. If that doesn't give you the quality you want you can browser through the User Contributed notes on the same page. Have you had a look at this Bag O' Tricks [webmasterworld.com] thread for the Image Upload and Thumbnail Generator?

As far as blocking non-image files you can a few edit checks. A recent discussion on security prompted this PHP Peer Code Review [webmasterworld.com] that has some answers for you.