如何在会话变量中存储照片上传? [多个PHP页面]

时间:2015-03-29 18:34:07

标签: php mysql session file-upload

我构建了这个webform向导,包含几个PHP页面。在这几页中,用户可以填写表单,数据会临时存储在会话中,最后一页会话用于存储MYSQL数据库中的所有数据。请帮帮我:)。

步骤-2.PHP

                /* IMAGE UPLOAD 1 */
            if (!empty($_FILES['fileFotograf1'])) {
               $target_file = $target_dir . basename($_FILES["fileFotograf1"]["name"]);
               $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

                if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
                    header('location:steps-2.php?error=1');
                    $uploadOk = 0;
                }else{
                       $_SESSION['ImagefileFotograf1'] = $_FILES["fileFotograf1"]["name"];
                       $_SESSION['TmpfileFotograf1'] = $_FILES["fileFotograf1"]["tmp_name"];
                     }
            }

            /* IMAGE UPLOAD 2 */

                if (!empty($_FILES['fileFotograf2'])) {
               $target_file = $target_dir . basename($_FILES["fileFotograf2"]["name"]);
               $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

                if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
                    header('location:steps-2.php?error=1');
                    $uploadOk = 0;
                }else{
                       $_SESSION['ImagefileFotograf2'] = $_FILES["fileFotograf2"]["name"];
                       $_SESSION['TmpfileFotograf2'] = $_FILES["fileFotograf2"]["tmp_name"];
                     }
            }

            /* IMAGE UPLOAD 3 */

                if (!empty($_FILES['fileFotograf3'])) {
               $target_file = $target_dir . basename($_FILES["fileFotograf3"]["name"]);
               $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

                if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
                    header('location:steps-2.php?error=1');
                    $uploadOk = 0;
                }else{
                       $_SESSION['ImagefileFotograf3'] = $_FILES["fileFotograf3"]["name"];
                       $_SESSION['TmpfileFotograf3'] = $_FILES["fileFotograf3"]["tmp_name"];
                     }
            }

            /* IMAGE UPLOAD 4 */
                if (!empty($_FILES['fileFotograf4'])) {
               $target_file = $target_dir . basename($_FILES["fileFotograf4"]["name"]);
               $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

                if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
                    header('location:steps-2.php?error=1');
                    $uploadOk = 0;
                }else{
                       $_SESSION['ImagefileFotograf4'] = $_FILES["fileFotograf4"]["name"];
                       $_SESSION['TmpfileFotograf4'] = $_FILES["fileFotograf4"]["tmp_name"];
                     }
            }

步骤-2(形式)的.PHP

    <div class="rowCol">
        <div class="fourCol">
            <label>Fotoğraf #1</label>
            <input data-parsley-id="9994" name="fileFotograf1" id="fileFotograf1" type="file"><ul id="parsley-id-9994" class="parsley-errors-list"></ul>
        </div>
        <div class="fourCol">
            <label>Fotoğraf #2</label>
            <input data-parsley-id="7220" name="fileFotograf2" id="fileFotograf2" type="file"><ul id="parsley-id-7220" class="parsley-errors-list"></ul>
        </div>
        <div class="fourCol">
            <label>Fotoğraf #3</label>
            <input data-parsley-id="5983" name="fileFotograf3" id="fileFotograf3" type="file"><ul id="parsley-id-5983" class="parsley-errors-list"></ul>
        </div>
        <div class="fourCol">
            <label>Fotoğraf #4</label>
            <input data-parsley-id="0867" name="fileFotograf4" id="fileFotograf4" type="file"><ul id="parsley-id-0867" class="parsley-errors-list"></ul>
        </div>
        <div class="clear"></div>
    </div>

步骤-6.php(尾页).PHP

    if (empty($_SESSION['ImagefileFotograf1']) || empty($_SESSION['ImagefileFotograf2']) || empty($_SESSION['ImagefileFotograf3']) || empty($_SESSION['ImagefileFotograf4'])) {
        $target_dir = "./uploads/pets/";
        @$target_file1 = $target_dir . basename($_SESSION['ImagefileFotograf1']);
        @$target_file2 = $target_dir . basename($_SESSION['ImagefileFotograf2']);
        @$target_file3 = $target_dir . basename($_SESSION['ImagefileFotograf3']);
        @$target_file4 = $target_dir . basename($_SESSION['ImagefileFotograf4']);
        $ImagefileFotograf1 = $_SESSION['ImagefileFotograf1'];
            if (move_uploaded_file($HTTP_POST_FILES['file']['tmp_name'],"/finallocation/".$HTTP_POST_FILES['file']['name']);) {
            }
            if (move_uploaded_file(@$_SESSION['TmpfileFotograf2'], $target_file2)) {
            }
            if (move_uploaded_file(@$_SESSION['TmpfileFotograf3'], $target_file3)) {
            }
            if (move_uploaded_file(@$_SESSION['TmpfileFotograf4'], $target_file4)) {
            }

    }

0 个答案:

没有答案