0

プロフィール画像をアップロードするためのこのコードを見つけました。

http://www.phpdevblog.eu/2011-04/combined/jquery-ajax-and-php-based-profile-image-upload-without-reloading-the-page.html#comments

すべて問題ありません。しかし、名前ファイル= user_idを設定したい

入力された非表示の user_id 値を php アップロード ファイル プロセスに渡す方法を教えてください。

var uploadURL = "processupload.php";
      $(document).ready(function(){
                $('a#uploadFile').file();
                $('a#delete').click(function(){
                      $('input#profileImageFile').val("");
                      $('img#profileImage').attr("src","/images/styles/profileBlank.jpg");
                      $('div#messageBox').html("Image deleted !");
                      $('div#messageBox').attr("class","success");
                      $('a#delete').hide();
                });
                $('input#uploadFile').file().choose(function(e, input) {

                    input.upload(uploadURL, function(res) {
                        if (res=="invalid"){
                            $('div#messageBox').attr("class","error");
                            $('div#messageBox').html("Invalid extension !");
                        }else{
                            $('div#messageBox').attr("class","success");
                            $('div#messageBox').html("Imagen cargada !");
                            $('img#profileImage').attr("src","/images/avatars/"+res);
                            $('input#profileImageFile').val(res);
                            $('a#delete').show();
                            $(this).remove();
                        }
                    }, '');                  
          });
           });

html

<div class="imageContainer">
            <img alt=""  src="/images/avatars/<?php echo $row_rs_user['user_image']; ?>" width="150" height="150" id="profileImage">
            <a href="#" id="uploadFile" title="Upload"><img alt=""  src="/images/styles/upload.jpg"></a>
            <a href="#" id="delete" title="Delete" style="display:none;position:relative;z-index:999999;"><img alt=""  src="/images/styles/delete.jpg"></a>
<input type="hidden" name="user_id" value="<?php echo $row_rs_user['user_id']; ?>">
            <div id="messageBox"></div>
    </div>

PHPアップロードプロセス

if(isset($_POST))
{
.
.
.
.
4

2 に答える 2

0

uploadURL を介して情報を渡すだけです。

input.upload(uploadURL + "?user_id=" + $("input[name=user_id]").val(), function(res) {});

ユーザー ID を保持する隠し入力の名前が「user_id」であることを確認してください。PHP のサーバー側では、変数の値を isset($_REQUEST['user_id']) で読み取ることができます。

于 2013-02-07T05:57:57.920 に答える
0

I'm not familiar with the plugin you are using to handle the uploads, but if the form elements are hitting the PHP as they should, you simply can call

$fileId = $_POST['user_id'];

これにより、PHP プロセスの変数が非表示の値に等しく設定されます。エラーが発生しないように、必ず ISSET 条件内に含めてください。

于 2013-01-29T20:36:39.890 に答える