javascript picture resize down if need, and submit it

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
freeAngel_007
Forum Newbie
Posts: 9
Joined: Thu Jun 19, 2008 12:23 pm

javascript picture resize down if need, and submit it

Post 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...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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

Post 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
freeAngel_007
Forum Newbie
Posts: 9
Joined: Thu Jun 19, 2008 12:23 pm

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

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post by Eran »

Are you the one uploading the images? why not resize them in a photo editing program instead?
freeAngel_007
Forum Newbie
Posts: 9
Joined: Thu Jun 19, 2008 12:23 pm

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

Post 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
Post Reply