我对此嗤之以鼻,试图将两种不同的想法结合在一起。他们每个人都是单独工作,但我试图整合它们。
我想要做的是在upload.php页面中定位动态创建的列表项,并将href =&#34; javascript:void(0)更改为index.php中的用户指定变量< / p>
index.php代码
<!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 is a link</a>
</p>
</div>
</body>
</html>
upload.php代码
<?php
if($_POST['image_form_submit'] == 1)
{
$images_arr = array();
foreach($_FILES['images']['name'] as $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 you want to upload and stored images into the "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 as $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 }
}
}
?>
就像我说的那样,我对此并不陌生,可能会有一个更加优雅的解决方案,但我已经远远没有找到狩猎和啄食......提前感谢任何帮助。