2011-10-25 14 views
0

ファイルのアップロードを使用するフォームがあります。アップロードボタンを押すと、データベースに行き、フォームに名前を表示します。jquery uploadifyを使用した複数のファイルアップロード

私の質問は、フォームを送信するまで、データベースに格納しないでください。誰でも私はonclick jQueryのアップロード設定を使用してファイルをアップロードするのを助けることができます。

答えて

0

Uploadify用のバックエンドPHPプロセッサを使用してファイルを処理して移動できますが、情報を$ _SESSION変数に格納できます。

$ _SESSIONデータを挿入するバックグラウンドで別のスクリプトを起動することができます。

プロセッサフ​​ァイル:

<?php 

@session_start() 

if (!empty($_FILES)) { // Process uploaded file 

    $upload_dir = '/path/to/uploads/'; // Set upload path WITH TRAILING SLASH 

    $file_temp = $_FILES['Filedata']['tmp_name']; // Retrieve temporary file path 
    $file_orig = basename($_FILES['Filedata']['name']) ; // Retrieve original file name 

    $file_save = time() . $file_orig; // Prepend filename with time stamp to avoid overwriting files 
    $target_path = $upload_dir . $file_save; // Prepand filename with the upload path 

    move_uploaded_file($file_temp, $target_path); // Move the file to the upload path using generated filename 

    $insert = array(
    'path' => $file_save, 
    'original' => $file_temp, 
    'date_created' => date('Y-m-d H:i:s') 
    ); 

    $_SESSION['uploadify_files'][] = $insert; // Set session data 

    echo '1'; // Success 
} 

ポストプロセッサフ​​ァイル:

:(さんは、それが命名されたと仮定しましょう "postprocess.php")

<?php 

@session_start() 

if (is_array($_SESSION['uploadify_files'])) { // Process stored data 

    foreach ($_SESSION['uploadify_files'] as $one_file) { 
     // Use the data... 
     $path = $one_file['path']; 
     $original = $one_file['original']; 
     $date = $one_file['date']; 
     mysql_query(" INSERT INTO files (path, original, date) VALUES ('$path', '$original', '$date'); "); 
    } 

    unset($_SESSION['uploadify_files']); // Remove the session data so it is not processed again in the next upload 
    echo 'OK'; // Report success 
} else echo 'FAILURE'; 

そして最終的にいくつかのjQueryは、後処理をトリガーします

$("#finish_button").live("click", function(){ 
    $.get('postprocess.php', function(data) { 
    if (data == 'OK') { 
     // Success ! 
     alert('Load was performed.'); 
    } else { 
     // Failure 
     alert('There was a problem.'); 
    } 
    }); 
}); 
+0

この情報は役に立ちましたか? –

関連する問題