2012-01-08 41 views
0

我的代码是一个上传表单,可将​​所有上传的文件重定向到PHP处理脚本。问题是,单击“提交”按钮后,它只会重定向到处理页面并停在那里,当上传成功时,php页面将被处理,然后重定向到另一个名为selectAlbum.php的页面。PHP脚本未处理

下面是形式的代码:

<html> 
<head> 
<title> Sample1 - File Upload on Directory </title> 
<style type="text/css"> 
/* jQuery lightBox plugin - Gallery style */ 
#form { 
    background-color: #aaa; 
    padding: 10px; 
    width: 520px; 
    border-left-width:center; 
} 
</style> 
</head> 
<body> 
<div id="form" align="center"> 
<form action="process.php" method="post" enctype="multipart/form-data"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> 
     Create an Album (limited to 10 images): <br /> 
     Album name (Please specify): 
    <input type="text" name="album_name" size="30" /> 
    <br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <input type="file" name="uploadedfile[]" /><br /> 
    <br /> 
    <input type="submit" value="Upload File" /> 
</form> 
</div> 

</body> 
</html> 

的PHP程序代码。 process.php:

<?php 

    $target_path = "galleryholder/" .$_POST['album_name']. "/"; 

    if(!file_exists($target_path)) 
    { 
     if(!mkdir($target_path, TRUE)) 
     { 
      die ("could not create the folder"); 
     } 
    } 
    else 
    { 
     for($count = 0; $count < count($_FILES['uploadedfile']); $count++) 
      { 
       $target_path = $target_path . basename($_FILES['uploadedfile']['name'][$count]); 
       $image_size[$count] = getimagesize($_FILES['uploadedfile']['tmp_name'][$count]); 

       if($image_size[$count] !== FALSE || ($image_size[$count]) != 0) 
       { 
         if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$count], $target_path)) 
         { 
         header('Location: selectAlbum.php'); 

         } 
         else 
         { 

          header('Location: uploader3.php'); 
         } 
       } 
       else 
       { 

        header('Location: uploader3.php'); 
       } 
      } 
    } 
?> 

当上传成功的话放在这里:

<html> 
<head> 
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script> 
<link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" /> 

<script type="text/javascript"> 
    $(function() { 
     $('#gallery a').lightBox(); 

     $('#gallery1 a').lightBox(); 
    }); 
    </script> 
    <style type="text/css"> 
    /* jQuery lightBox plugin - Gallery style */ 
    #gallery { 
     background-color: #aaa; 
     padding: 10px; 
     width: 520px; 
     background-position:top; 
    } 
    #gallery ul { list-style: none; } 
    #gallery ul li { display: inline; } 
    #gallery ul img { 
     border: 5px solid #3e3e3e; 
     border-width: 5px 5px 20px; 
    } 
    #gallery ul a:hover img { 
     border: 5px solid #fff; 
     border-width: 5px 5px 20px; 
     color: #fff; 
    } 
    #gallery ul a:hover { color: #fff; } 
</style> 
</head> 
<body> 

<?php 
$page = $_SERVER['PHP_SELF']; 

//settings 
$column = 5; 

//directories 

$base = "galleryholder"; 
//$thumbs ="thumbs"; 

//get album 
$get_album = $_GET['album']; 
if(!$get_album) 
{ 
    echo "<b> Select an Album:</b><p />"; 
    $handle = opendir($base); 
    while(($file = readdir($handle))!== FALSE) 
    { 
     if(is_dir($base."/".$file) && $file != "." && $file != "..") 
     { 
      echo "<a href='$page?album=$file'>$file</a><br />"; //$file. "<br />"; 
     } 
    } 
} 
else 
{ 
    //echo "An album has been clicked."; 
    if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL) 
    { 
     echo "The album doesn't does not exist"; 
    } 
    else 
    { 
     echo "<h2 id='example'><b>$get_album</b></h2><p />"; 
     echo "<div align='center' id='gallery'>"; 
     echo "<ul>";  
     $handle = opendir($base."/". $get_album); 
     while(($file = readdir($handle))!== FALSE) 
     { 
      if($file != "." && $file != "..") 
      { 

       echo "<li>"; 
       echo "<a href='$base/$get_album/$file'><img src='$base/$get_album/$file' height='100' width='100'>"; 
       echo "</li>"; 

      } 

     } 
     echo "</ul>"; 
    echo "</div>"; 
    } 
} 
?> 

</body> 
</html> 
+4

始终'模具()'或'退出;'设置位置报头之后,停止脚本进一步执行。 – 2012-01-08 08:43:34

+0

@Kolink谢谢你..我仍然在这些PHP函数中是新的..谢谢你! :D – SimonCode 2012-01-08 08:48:05

+0

@Kolink它不工作..仍然代码不创建文件夹.. T_T我该怎么办? – SimonCode 2012-01-08 11:52:07

回答

2

您的问题是文件权限。 PHP需要777个文件上传。

使用UNMASK()指定文件在未经许可的,然后上传。

见下面链接,UNMASK http://www.w3schools.com/php/func_filesystem_umask.asp

,并检查您的mkdir()函数的第二个参数是模式,但你给出TRUE,并创建递归目录。

参考此链接MKDIR()函数http://www.w3schools.com/php/func_filesystem_mkdir.asp

+0

我已经做了什么,你问我做..仍然有错误.. :(它的MKDIR侧给出了一个错误。我怎样才能解决这个问题呢?>感谢提前。 – SimonCode 2012-01-08 12:15:22

+1

@SimonCode,我已经更新了我的答案, ?检查您的mkdir()函数和Windows flatform不支持​​模式 – 2012-01-08 12:22:35

+0

我在哪里可以找到Windows flatform模式 – SimonCode 2012-01-08 12:34:33