0

My code is an upload form that redirects all the uploaded files to a PHP processing script. The problem is, after I click "Submit" button, it redirects only to the processing page and stops there, the php page supposedly will process then redirect to another page called selectAlbum.php when upload is successful.

Here is the code for the forms:

 <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>

The code for the PHP PROCESS. 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');
                }
            }
    }
?>

When upload is successful it goes here:

<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>
3
  • 4
    Always die() or exit; after setting a Location header, to stop the script executing further. Commented Jan 8, 2012 at 8:43
  • @Kolink thank you for that.. Im still new in those php functions.. THanks by the way! :D Commented Jan 8, 2012 at 8:48
  • @Kolink its not working.. still the code is not creating the folder.. T_T what Should I do? Commented Jan 8, 2012 at 11:52

2 Answers 2

2

Your problem is File Permission. PHP needs 777 for file uploads.

Use unmask() to assign file permisson and then upload.

See below link for unmask http://www.w3schools.com/php/func_filesystem_umask.asp

and check your mkdir() function the second parameter is mode but you given as TRUE, and create recursive directory.

Refer this link for mkdir() function http://www.w3schools.com/php/func_filesystem_mkdir.asp

Sign up to request clarification or add additional context in comments.

14 Comments

i already did what you asked me to do.. still got errors.. :( it gives an error on the mkdir side.. how can I resolve this problem?> thanks ahead.
@SimonCode, I have updated my answer , check your mkdir() function and windows flatform will not support mode
where can I find the windows flatform mode?
I think @RobinMichaelPoothurai wanted to say not flatform but platform and better this link: php.net/manual/en/function.mkdir.php
@SimonCode php.net/manual/en/function.mkdir.php read here. Robin tryed tell you that mode argument ignored in mkdir. Text from php.net: mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using [link](http://www.php.net/manual/en/function.umask.php).
|
0

I suggest that the problem is at the beginning of your process file. Additionally in your form you are using an array process but nothing indicated the value of the individual element. My preference would be to assign different names to the file lines, then post them to the process file and create the array there.

 <input type='file' name=uploadedfile[] value= ???>

 $filename = "/folder/" . $dirname . "/";

 if (file_exists($filename)) {
      echo "The directory $dirname exists."; 
      // do something such as redirect back to forms
 } else {
      mkdir("folder/" . $dirname, 0755);
      echo "The directory $dirname was successfully created.";
      // start loading files into gallery instead of exit
 } // close else

You may want to try reworking your form page by pulling the gallery directories and putting them into a select/option arrangement. The below that selection have the opportunity to enter a new directory.

Of curse you will have to change your process coding to select either a current directory or create a new one to upload files to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.