Page 1 of 1

javascript picture resize down if need, and submit it

Posted: Tue Jun 24, 2008 3:11 pm
by freeAngel_007
Hi all,

i have a problem with javascript (i am new in javascript).

i need submit picture file form to php script. But first I need to check size of the image if is need then resize this image down and then submit it resized.

i have this code but it dont submit file if it resize image so the question is why?

javascript:

Code: Select all

 
<!--
function submitFileForm(form)
{
    form.picturefile.value = resize(form.picturefile);
    document.fileform.submit();
}
 
function resize(which, max) {
  var elem = document.getElementById(which);
  if (elem == undefined || elem == null) return false;
  if (max == undefined) max = 100;
  if (elem.width > elem.height) {
    if (elem.width > max) elem.width = max;
  } else {
    if (elem.height > max) elem.height = max;
  }
  
  return elem;
}
//-->
 
 
HTML form:

Code: Select all

 
<form method="POST" enctype="multipart/form-data" action="upload.php" style="margin-top: 0px;" name="fileform" >
<tr align="right" >
    <td style="padding-top: 10px;padding-right: 5px;">
 
                <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
                
                <b>Insert file:</b> <input  type="file" name="picturefile" />
    </td>
</tr>
<tr align="right">
    <td style="padding-top: 10px;padding-right: 5px; padding-bottom: 5px;">
        <input type="submit" value="Prida? obrázok" onClick="submitFileForm()" />
    </td>
</tr>
<tr>
<td style="text-align: center;padding-bottom:10px;padding-top:4px;">
 
</td>
 
</tr>
</form>
</table>
 
thx for any advices...

Re: javascript picture resize down if need, and submit it

Posted: Tue Jun 24, 2008 4:12 pm
by Kieran Huggins
You can't resize the image in javascript, but you can in PHP after the form is submitted.

Check out http://www.php.net/gd

Re: javascript picture resize down if need, and submit it

Posted: Tue Jun 24, 2008 4:29 pm
by freeAngel_007
but the problem is that if i want upload larger image (more than 2MB) it will not upload that file to server and then its impossible to use GD

Re: javascript picture resize down if need, and submit it

Posted: Tue Jun 24, 2008 5:48 pm
by Kieran Huggins
the only way I've seen it done on the client side if with a java applet, but that's beyond me.

Maybe you could increase the POST limit?

Re: javascript picture resize down if need, and submit it

Posted: Tue Jun 24, 2008 5:51 pm
by Eran
Are you the one uploading the images? why not resize them in a photo editing program instead?

Re: javascript picture resize down if need, and submit it

Posted: Wed Jun 25, 2008 3:20 am
by freeAngel_007
no I need it to upload pictures on my website server throught html form..

so I was wondering how to do it by automatic process ...

thx for your posts