English 中文(简体)
单位:千美元
原标题:where to display $_SESSION variable below

我试图找回一个文件上载的名字,并将其输入名单上。 问题是,从“SESSION”变量中检索的档案名称始终是最新档案,然后是没有变化的。

例如,如果我把这些档案上载到服务器以下的话:

desert.jpg
tulips.jpg
lighthouse.jpg
desert_2.jpg

然后,它应从_SESSION美元中填写的档案名称应为:

desert.jpg
tulips.jpg
lighthouse.jpg
desert_2.jpg

但是,在从屏幕上的“SESSION”美元中检索的文档名称方面,下文对此作了评估:

desert.jpg
desert.jpg
desert.jpg
desert.jpg

如何确定,以便在档案上上载到服务器时,其档案名称被附在名单上?

下面是“javascript”功能,即“SESSION”变量在“json”代码中,显示屏幕上文档的名称,将其贴上:

  function stopImageUpload(success){

          var imagename = <?php echo json_encode(isset($_SESSION [ fileImage ][ name ]) ? $_SESSION [ fileImage ][ name ] : null); ?>;
          if (success == 1){
             $( .listImage ).append(imagename +  <br/> );
          }
          else {

            $( .listImage ).append( No File );
          }

    return true;

    }

The Below is the php Code where it uploads the file:

<?php

session_start();

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

$allowedTypes = array (
        "image/jpeg",
        "image/gif",
        "image/pjpeg",
        "image/jpg",
        "image/png",
        "image/tif" 
);

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

    $fileName = $_FILES [ fileImage ] [ name ];
    $fileSize = $_FILES [ fileImage ] [ size ];
    $fileTemp = $_FILES [ fileImage ] [ tmp_name ];
    $fileType = $_FILES [ fileImage ] [ type ];

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

    if (empty ( $fileName ))
        continue;

    if (! in_array ( $fileType, $allowedTypes )) {
        $errors [] = "File Type is not accepted";

    }

    if(!is_writable($dirImage ))
    {
        $errors [] = "File Destination not writeable";
    }


    $fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;
    $filePrifix = basename ( $fileName, "." . $fileExt );
    $i = 0;
    while ( file_exists ( $fileDst ) ) {
        $i ++;
        $fileDst = $dirImage . DIRECTORY_SEPARATOR . $filePrifix . "_" . $i . "." . $fileExt;

    }
    // Move the file

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


        }
    }

}

$_SESSION [ fileImage ][] = $_FILES [ fileImage ][ name ];

?>

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

在适当网页上,有1名初等干事,可检索到_SESSION:

function stopImageUpload(success){

      var imagename = <?php echo json_encode(isset($_SESSION [ fileImage ]) ? $_SESSION [ fileImage ] : null); ?>;
      if (success == 1){
         $( .listImage ).append(imagename +  <br/> );
      }
      else {
        $( .listImage ).append( <br/> );
      }

return true;

}
问题回答

<代码>_SESSION [ fileImage ][] =_$_FILES [ fileImage ][ name]; und $_SESSION [ fileImage ][ name] =_$_FILES [ fileImage ][ name];





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签