0

$_SESSION['imagename']imageupload.php (別のページ) から取得すると思われる場所の下に、javascript 変数があります。

var imagename = <?php echo json_encode(isset($_SESSION['imagename']) ? $_SESSION['imagename'] : null); ?>;

しかし、私の質問は、セッション変数にファイルの名前が含まれ、上記の変数で取得できるように、このコードをphpスクリプトのどこに配置すればよいですか?

if (isset($_POST['fileImage'])) { // fileImage is the name of the file input
  $_SESSION['imagename'] =  $_FILES['fileImage']['name'];
}

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

以下はphpスクリプトです。

$result = 0;

if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {  

    $parts = explode(".",$_FILES['fileImage']['name']);
    $ext = array_pop($parts);
    $base = implode(".",$parts);
    $n = 2;

    while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
    $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;

    move_uploaded_file($_FILES["fileImage"]["tmp_name"], 
    "ImageFiles/" . $_FILES["fileImage"]["name"]);
    $result = 1;

}
    else
      {
      move_uploaded_file($_FILES["fileImage"]["tmp_name"],
      "ImageFiles/" . $_FILES["fileImage"]["name"]);
      $result = 1;


      }

?>

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

1 に答える 1

0
    $result = 0;

    if (isset($_POST['fileImage']) && ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))){
          //you must check for file type, else your website could be hacked.
       if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) { 
          //... 
       }
       else{
          //...
       }
    }

    $_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
于 2012-04-22T00:42:44.143 に答える