Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 上传完文件后,如何在php中禁用按钮选择文件上传?_Javascript_Php_Mysql - Fatal编程技术网

Javascript 上传完文件后,如何在php中禁用按钮选择文件上传?

Javascript 上传完文件后,如何在php中禁用按钮选择文件上传?,javascript,php,mysql,Javascript,Php,Mysql,如果我们有5个按钮choose file to upload file,并希望在完成每个按钮的上传后自动禁用该按钮,那么我们如何知道“A”按钮choose file在表db mysql中有行“A”。因此,如果用户注销一次上载3个文件,则会再次登录。他只看到2个按钮选择启用的文件?谢谢你的帮助 这是我的代码: 上传_image.php <table align="center" width="800" height="500" class="tengah"> <tr> &l

如果我们有5个按钮choose file to upload file,并希望在完成每个按钮的上传后自动禁用该按钮,那么我们如何知道“A”按钮choose file在表db mysql中有行“A”。因此,如果用户注销一次上载3个文件,则会再次登录。他只看到2个按钮选择启用的文件?谢谢你的帮助

这是我的代码:

上传_image.php

<table align="center" width="800" height="500" class="tengah">
<tr>
<td align="center"><img src="img/logoo.fw.png"></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<form action="multiple_upload_image.php" method="post" enctype="multipart/form-data" name="form1"     id="form1">
<td align="center"><img src="img/upload.fw.png"><br><br>
1. Select Image : &nbsp;<input name="ufile[]" type="file" id="ufile[]" size="50" /><br><br>
2. Select Image : &nbsp;<input name="ufile[]" type="file" id="ufile[]" size="50" /><br><br>
3. Select Image : &nbsp;<input name="ufile[]" type="file" id="ufile[]" size="50" /><br><br>
4. Select Image : &nbsp;<input name="ufile[]" type="file" id="ufile[]" size="50" /><br><br>
5. Select Image : &nbsp;<input name="ufile[]" type="file" id="ufile[]" size="50" /><br><br>
<input type="submit" name="Submit" value="Upload" align="right"/> </form>
<a href="home.php"><input type="submit" name="Submit" value="Finished"  align="right"/></a><br><br>
*) Total Max Upload only 10MB
</td>
</tr>

</table>



1.选择图像:

2.选择图像:

3.选择图像:

4.选择图像:

5.选择图像:



*)总最大上载容量仅为10MB
下面是我的php代码:

<?php
error_reporting(E_ALL^(E_NOTICE | E_WARNING));
set_time_limit(0);
session_start();
$username=$_SESSION['userr'];
$password=$_SESSION['passw'];
$user_id=$_SESSION['usr_id'];
mysql_connect("localhost","root","");
mysql_select_db("person");
if(isset($_FILES['ufile'])){
$errors= array();
foreach($_FILES['ufile']['tmp_name'] as $key => $tmp_name ){
    $file_name = $key.$_FILES['ufile']['name'][$key];
    $file_size =$_FILES['ufile']['size'][$key];
    $file_tmp =$_FILES['ufile']['tmp_name'][$key];
    $file_type=$_FILES['ufile']['type'][$key];  
    if($file_size > 30000000){
    $errors[]='File size must be less than 10 MB';
    }   
mysql_connect("localhost","root","");
mysql_select_db("person");  
$query = "INSERT INTO image (user_id, name, type, size ) ".
"VALUES ('$user_id','$file_name','$file_type','$file_size')"; 
mysql_query($query) or die('Error, query failed');
move_uploaded_file($file_tmp,"image_file/".$file_name);
}
mysql_query($query);        

    }else{
            print_r($errors);
    }

if(empty($error)){
    echo '<script type=text/javascript>
alert("Registration was succeed");
window.location.href = "home.php";
</script>';
}
?>

上传开始时,需要将一个cookie值设置为true,并定期使用jquery cookie检查相同的cookie值

将要上载的php代码结束处的cookie值设置为false

这样,JS cookie代码中就会出现false,您可以调用按钮禁用JS代码

客户端源代码-Javscript

function getCookie( name ) {
   var parts = document.cookie.split(name + "=");
   if (parts.length == 2) return parts.pop().split(";").shift();
}

function expireCookie( cName ) {
    document.cookie =  encodeURIComponent( cName ) + "=deleted; expires=" + new Date( 0 ).toUTCString();
}

function setCursor( docStyle, buttonStyle ) {
    document.getElementById( "doc" ).style.cursor = docStyle;
    document.getElementById( "button-id" ).style.cursor = buttonStyle;
}

function setFormToken() {
    var downloadToken = new Date().getTime();
    document.getElementById( "downloadToken" ).value = downloadToken;
    return downloadToken;
}

var downloadTimer;
var attempts = 30;

// Prevents double-submits by waiting for a cookie from the server.
function blockResubmit() {
var downloadToken = setFormToken();
setCursor( "wait", "wait" );

downloadTimer = window.setInterval( function() {
  var token = getCookie( "downloadToken" );

  if( (token == downloadToken) || (attempts == 0) ) {
    unblockSubmit();
  }

      attempts--;
    }, 1000 );
  }

function unblockSubmit() {
    setCursor( "auto", "pointer" );
    window.clearInterval( downloadTimer );
    expireCookie( "downloadToken" );
}
服务器代码-PHP

$TOKEN = "downloadToken";

// Sets a cookie so that when the download begins the browser can
// unblock the submit button (thus helping to prevent multiple clicks).
// The false parameter allows the cookie to be exposed to JavaScript.
$this->setCookieToken( $TOKEN, $_GET[ $TOKEN ], false );

$result = $this->sendFile();
其中:

public function setCookieToken(
$cookieName, $cookieValue, $httpOnly = true, $secure = false ) {

// See: http://stackoverflow.com/a/1459794/59087
// See: http://shiflett.org/blog/2006/mar/server-name-versus-http-host
// See: http://stackoverflow.com/a/3290474/59087
setcookie(
  $cookieName,
  $cookieValue,
  2147483647,            // expires January 1, 2038
  "/",                   // your path
  $_SERVER["HTTP_HOST"], // your domain
  $secure,               // Use true over HTTPS
  $httpOnly              // Set true for $AUTH_COOKIE_NAME
);
}

哪里是
我尝试过的
部分请发布您的源代码。从查看您的源代码来看,一旦用户提交表单,它会将他们导航到multiple\u upload\u image.php,这样您的表单就不会显示。不能禁用不存在的按钮。如果将发布方法更改为使用ajax,则可以将媒体发布到php文件中,并将客户端保持在当前页面上。如果您对使用ajax发布媒体感兴趣,请检查是否有任何用处,然后请务必投票支持。是的,我想尝试使用ajax,让我们检查一下。谢谢。或者根据上传的方式,你可以使用eventlisteners。如果Intan使用ajax发布,那么就不需要使用cookie。因此等待源代码。嗨,Lalit Sharma-谢谢你的解释。我将尝试上面的输入代码。如果我有进一步的担忧或问题,也许我仍然需要你的帮助。谢谢。