2

当我打开网页时,它只显示一个空白页面。你知道它为什么这样做吗?可能是因为 $_SESSION 中的 [] 吗?错误控制台上没有 javascript 错误,屏幕上也没有 php 错误。

下面是发生附加的 javascript 代码:

    <?php
    session_start();

    $idx = count($_SESSION ['fileImage'] - 1);
    $output = isset($_SESSION ['fileImage'][$idx]) ? $_SESSION ['fileImage'][$idx]['name'] : "";

    ?>

              function stopImageUpload(success){

              var imageNameArray = ['<?php echo $output ?>'];
              var result = '';



              if (success == 1){
                 result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';

                    for(var i=0;i<imageNameArray.length;i++)
            {
                 $('.listImage').append(imageNameArray[i]+ '<br/>');

             }

              }
              else {
                 result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
              }

        return true;

        }

下面是 php 脚本,它从上面的 javascript 函数上传另一个页面上的文件:

        <?php

            session_start();

            $result = 0;
            $errors = array ();
            $dirImage = "ImageFiles/";


        if (isset ( $_FILES ['fileImage'] ) && $_FILES ["fileImage"] ["error"] == UPLOAD_ERR_OK) {

        $fileName = $_FILES ['fileImage'] ['name'];

        $fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION );
        $fileExt = strtolower ( $fileExt );


        $fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;

                if (count ( $errors ) == 0) {
                    if (move_uploaded_file ( $fileTemp, $fileDst )) {
                        $result = 1;


                    }
                }

            }

    $_SESSION ['fileImage'][] = array('name' => $_FILES ['fileImage']['name']);

            ?>

        <script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result;?>);</script>
4

1 回答 1

0
$idx = count($_SESSION ['fileImage'] - 1);

应该

$idx = count($_SESSION ['fileImage']) -1 ;

var imageNameArray = new Array();
imageNameArray = <?php echo $output ?>;

应该成为

var imageNameArray = ['<?php echo $output ?>'];
于 2012-04-28T12:38:57.267 回答