Jump to content
Vz19JDw3ExqZ

PHP in javascript array

Recommended Posts

Am un array in javascript de acest fel:


img = new Array('upload/img1.jpg','upload/img2.jpg');

si as vrea sa am ceva de genul:


img = new Array('upload/"<?php echo $post_img1; ?>"', 'upload/"<?php echo $post_img2; ?>"'');

cum as putea face chestia asta?

Adica vreau sa preiau cu php numele imaginii postate si sa o adaug in array-ul javascript.

Link to comment
Share on other sites


<html>
<body>
<script type="text/javascript">
var array = new Array(
'upload/'<?php echo urlencode($post_img1); ?>,
'upload/'<?php echo urlencode($post_img2); ?>
);
</script>
</body>
</html>

PS: Asta doar dac? codul javascript este incorporat în fi?ierul PHP... dac? nu, po?i folosi post, get

Edited by EAdrian
GarryOne is right
Link to comment
Share on other sites

Nu ai fost prea explicit de aceea nici nu am inteles mare lucru.

Relateaza mai in detalii cum se intampla actiunea.

Cum vrei s-o iei, dupa ce se face submit? Daca da, pui pur si simplu "img = new Array('upload/'.$_FILES['file']['name'].');"

@EAdrian, tu practic ai rescris inca o data ce a scris el in primul post.

Si unde e chestia aia:

'upload/'+ <?php echo urlencode($post_img1); ?>

nu ai de ce sa pui plus pentru ca nu concatenezi cu cod javascript. Corect ar fi

'upload/<?php echo urlencode($post_img1); ?>'

Edited by GarryOne
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...