Jump to content

[SOLVED] php get image height without the use of input box?


Recommended Posts

I'm looking around and it looks like there is lots of good info on pulling a var from php and using it in javascript, but no the other way around. All the info I can find says to just use hidden input boxes to hold the data, then post them with a submit button. But I have like 40 images, and I want to store their 'left' 'top' width' height'. Thats a lot of hidden input boxes to write (160+). It would be nice not to have those html'd into my script. Is there anyway to get the image height and set it as php data without a input box?

 

Example:

 

NOT THIS ----->

 

<form method="post">

<input style="display:none" name="some image height">

<input submit>

</form>

 

--------------------------------------------------------------------

THIS ------->

 

document.getElementById("some image").height = $post_imageheight[];

 

 

I'm not sure if I explained this clearly enough. Let me know if you need more detail. thanks

not sure if this would help you:

<form action='process.php' method='post'>
<input type='hidden' id='hidddenElement1' name='theHeights' />
<input type='submit' value='Submit!' />
</form>

<script type='text/javascript'>
var str = "";
var images = Array("someImage1","someImage2","someImage3","someImage4","someImage5");
for(i=0;i<4;i++) {
  str += images[i] + "=" + document.getElementById(images[i]).height + "&";
}
str += images[4] + "=" + document.getElementById(images[4]).height;
document.getElementById("hiddenElement1").value = str;
</script>

Then in 'process.php':

<?php
parse_str($_POST['theHeights']);
?>

Obviously the code abouve isn't complete, but is it approximately what you're looking for?

 

Hope it helps.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.