Change href in another PHP page using a variable -
i'm brand new , trying scab 2 different ideas. each of them work individually, i'm trying integrate them.
- i able upload , image (which creates list itme href="javascript:void(0).
- i can allow user input assign url existing text link.
what i'm trying target dynamically created list item in upload.php page , change href="javascript:void(0) user specified variable index.php
index.php code
<!doctype html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>image upload</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script type="text/javascript" src="jquery.form.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#images').on('change',function(){ $('#multiple_upload_form').ajaxform({ target:'#images_preview', beforesubmit:function(e){ $('.uploading').show(); }, success:function(e){ $('.uploading').hide(); }, error:function(e){ } }).submit(); }); }); </script> </head> <body> <div style="margin-top:50px;"> <div class="upload_div" > <form name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php"> <input type="hidden" name="image_form_submit" value="1"/> <label>choose image</label> <input type="file" name="images[]" id="images" multiple > <div class="uploading none"> <label> </label> <img src="uploading.gif"/> </div> </form> </div> <div class="gallery" id="images_preview"> </div> </div> <div class="form_div" id="url_input"> <form id="form1"> url - example http://www.yourdomain.com: <input name="name" type="text" size="20"> </form> <button onclick="outputname()">submit</button> <script> function outputname() { var x,y,name,a,b,answer; x=document.getelementbyid("form1") ; y=x.elements["name"].value; document.getelementbyid("upload.php#web").setattribute("href",y); } </script> <p id="demo"> <a id="link">this link</a> </p> </div> </body> </html>
upload.php code
<?php if($_post['image_form_submit'] == 1) { $images_arr = array(); foreach($_files['images']['name'] $key=>$val){ $image_name = $_files['images']['name'][$key]; $tmp_name = $_files['images']['tmp_name'][$key]; $size = $_files['images']['size'][$key]; $type = $_files['images']['type'][$key]; $error = $_files['images']['error'][$key]; ############ remove comments if want upload , stored images "uploads/" folder ############# /*$target_dir = "uploads/"; $target_file = $target_dir.$_files['images']['name'][$key]; if(move_uploaded_file($_files['images']['tmp_name'][$key],$target_file)){ $images_arr[] = $target_file; }*/ //display images without stored $extra_info = getimagesize($_files['images']['tmp_name'][$key]); $images_arr[] = "data:" . $extra_info["mime"] . ";base64," . base64_encode(file_get_contents($_files['images']['tmp_name'][$key])); } //generate images view if(!empty($images_arr)){ $count=0; foreach($images_arr $image_src){ $count++?> <ul class="reorder_ul reorder-photos-list"> <li id="image_li_<?php echo $count; ?>" class="ui-sortable-handle"> <a href="javascript:void(0);" style="float:none;" class="image_link"><img src="<?php echo $image_src; ?>" alt=""></a> </li> </ul> <?php } } } ?>
like said, i'm brand new , there may far more elegant solution, i've gotten far hunting , pecking... in advance help.
Comments
Post a Comment