我試圖從後一種形式的隱藏輸入類型的隨機值..但它沒有發表任何值.. ..PHP mt_rand使用功能後的值不工作
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.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>
<form method="post" name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
<input type="hidden" name="randnum" id ="randnum" value="<?php echo mt_rand(1000,10000000); ?>" />
<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>
和這是upload.php的
if($_POST['image_form_submit'] == 1)
{
$rand = $_POST['randnum'];
$con=new PDO("mysql:host=localhost;dbname=newimg","root","");
$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];
$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;
$addnew=$con->prepare("INSERT INTO attempt010(link,name,size,type)VALUES('$rand','$image_name','$size','$type')");
$addnew->execute();
}
}
$fetch_imgid=$con->prepare("SELECT * FROM attempt010 where link='$rand'");
$fetch_imgid->setFetchMode(PDO:: FETCH_ASSOC);
$fetch_imgid->execute();
?>
我想每一個表單被張貼的時間存儲的隨機數...
哎,請使用echo打印值例如。價值=「<?php回聲mt_rand(1000,10000)」;?> –
我已經上傳了完整的代碼... –
它張貼了其他圖片信息... –