SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uploading images

    I'm new to uploading images and I'm using this script to help me. I keep getting this error though and can't figure out what this script is doing with the file once it gets it. I'll post the relevant code and the error.

    PHP Code:
    function addimages($pic$id)
    {
    $n count($pic);
    for (
    $i=0$i<$n$i++)
    {
    // define the base image dir 
    $base_img_dir "./images/listings/";

    // define location of image conversion programs
    $img_conv_dir "./bin/";

    // new file name
    $filename $base_img_dir.$id;

    // move uploaded file to destination
    move_uploaded_file($pic[$n], $filename);

    // retrieve image info
    $imginfo getimagesize($filename); 
    Code:
    Warning: getimagesize(./images/dfas) [function.getimagesize]: failed to open stream: No such file or directory in ...\includes\listing.inc.php on line 21

  2. #2
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    curious, why is it you listed

    "./images/listings/"

    but the error shows

    ./images/dfas

    and I bet you have to give it the full path.
    success is not by chance, it is by choice.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $pic[$i] not $pic[$n] couse $i is boolean of $n
    and like sahajin said... u have to give full path to your upload directory.
    cheers

  4. #4
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New code, new problem. I want to change the name of the file to a unique number but keep the variable name $pic[]. I think have this code in there properly, but, don't know what to do with move_uploaded_file.

    PHP Code:
    function addimages($pic$id)
    {
    $n count($pic);
    for (
    $i=0$i<$n$i++)
    {
    // define the base image dir 
    $base_img_dir "./images/listings/";

    // define location of image conversion programs
    $img_conv_dir "./bin/";

    // generate unique id for use in filename
    $uniq uniqid("");

    // new file name
    $pic[$i] = $base_img_dir.$uniq;  //?????

    // move uploaded file to destination
    move_uploaded_file($pic[$i], $filename);  //???????????

    // retrieve image info
    $imginfo getimagesize($filename); 

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function addimages() { 
    global 
    $uploaddir// note to insert full path to upload dir
    for($i 0$i $_POST["userfile"]; ++$i) { 
    // userfile is input file name
    $uploadfile $uploaddir $_FILES["userfile[$i]"]["name"];
    $pic $_FILES["userfile[$i]"]["name"];
    move_uploaded_file($_FILES["userfile[$i]"]["tmp_name"], $uploadfile)
    $imginfo getimagesize($_FILES["userfile[$i]"]["name"]); 
    }

    note for input type file name userfile[]
    cheers

  6. #6
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two problems now. It's saving the filename in the database as the filename that I uploaded, not the unique. And the loop isn't stopping if there is only one file, it's going through all 7.

  7. #7
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New code

    PHP Code:
    function addimages($pic$id)
    {
    $n count($pic);
    for (
    $i=0$i<$n$i++)
    {
    // define the base image dir 
    $base_img_dir "./images/listings/";

    // define location of image conversion programs
    $img_conv_dir "./bin/";
    // generate unique id for use in filename
    $uniq uniqid("");

    // new file name
    $filename $base_img_dir.$uniq;

    // move uploaded file to destination
    move_uploaded_file($pic[$i], $filename);

    // retrieve image info
    $imginfo getimagesize($pic[$i]); 
    New Error:

    Warning: getimagesize(logo.gif) [function.getimagesize]: failed to open stream: No such file or directory in c:\wamp\www\admin\includes\listing.inc.php on line 23

  8. #8
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by subnet_rx
    New code

    New Error:

    Warning: getimagesize(logo.gif) [function.getimagesize]: failed to open stream: No such file or directory in c:\wamp\www\admin\includes\listing.inc.php on line 23
    I already told you what to do.
    Quote Originally Posted by Sahajin
    you have to give it the full path.
    success is not by chance, it is by choice.

  9. #9
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's not it. I think I'm just going to look for another script.

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function addimages() {
    global 
    $uploaddir// note to insert full path to upload dir
    for($i 0$i $_POST["userfile"]; ++$i) {
    // userfile is input file name
    if(!empty($_POST["userfile[$i]"])) {
    $uploadfile $uploaddir $_FILES["userfile[$i]"]["name"];
    $pic $_FILES["userfile[$i]"]["name"];
    move_uploaded_file($_FILES["userfile[$i]"]["tmp_name"], $uploadfile)
    $imginfo getimagesize($_FILES["userfile[$i]"]["name"]);
    }
    }

    why u need the uniq id?
    do u have different pics with the same name?

  11. #11
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, it's possible that they will have the same name.

    Right now, it's timing out on the line below. I am giving it the full path, does it matter that this is in Windows so the path is C:\\wamp\\...? Also, am I using the right naming scheme for multiple pictures? I have used arrays before in forms with no problems.

    PHP Code:
    if(!empty($_POST["pic[$i]"])) 

    Here is the form code.

    Code:
    <tr>
        <td bgcolor="#EEEEEE"><strong>Photo 1</strong></td>
        <td>
              <div align="left">
                <input name="pic[]" type="file" size="30">
            &nbsp;</div></td></tr>
      <tr>
    Last edited by subnet_rx; Nov 19, 2004 at 13:00.

  12. #12
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for windows the slashes go the oposite way and you don't need the C: in there. you need the path form your htdocs or webroot folder. not the whole path on the machine.

    look into is_uploaded_file() too. that will tell you if it is uploaded or empty.
    success is not by chance, it is by choice.

  13. #13
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, path changed, here is what the var_dump is showing. From looking at it, it seems like it should be $_FILES[$pic][$name[$i]], but this causes the same timeout error on the same line. Here is the code var_dump:

    Code:
    array(1) { ["pic"]=> array(5) { ["name"]=> array(7) { [0]=> string(17) 
    "1_white-house.jpg" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" 
    [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" } ["type"]=> array(7) {
     [0]=> string(11) "image/pjpeg" [1]=> string(0) "" [2]=> string(0) "" [3]=> 
    string(0) "" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" } 
    ["tmp_name"]=> array(7) { [0]=> string(26) 
    "C:\WINDOWS\TEMP\phpACA.tmp" [1]=> string(0) "" [2]=> string(0) "" [3]=> 
    string(0) "" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" } ["error"]=>
     array(7) { [0]=> int(0) [1]=> int(4) [2]=> int(4) [3]=> int(4) [4]=> int(4) 
    [5]=> int(4) [6]=> int(4) } ["size"]=> array(7) { [0]=> int(82914) [1]=> int(0)
     [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> int(0) } } }
    Here is the current code
    PHP Code:
    function addimages($_POST$_FILES
    {
        global 
    $uploaddir;
        
    $uploaddir "/agentsitenow/admin/images/listings/";  //Path from webserver root
        
    $picture $_FILES["pic"]; 
        for(
    $i 0$i $picture; ++$i
        {
            
    // userfile is input file name
            
    if(!empty($picture["name[$i]"]))   //timeout here
            
    {
                
    $uploadfile $uploaddir $picture["name[$i]"];
                
    $pic $picture["name[$i]"];
                
    move_uploaded_file($picture["tmp_name[$i]"], $uploadfile);
                
    $imginfo getimagesize($picture["name[$i]"]); 

  14. #14
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after several var_dump outputs, and editing the code. I have finally made some progress. It echo's that the file has been uploaded, and then times out, I guess looking for the next file.

    CORRECTION: File is being uploaded. I just need to solve the problem of how to tell the script there are no more files that have been uploaded.


    Here is the complete code, with the current errors

    PHP Code:
    function addimages($_POST$_FILES
    {
        
    var_dump($_FILES);
        global 
    $uploaddir// note to insert full path to upload dir
        
    $uploaddir "c:\wamp\www\\agentsitenow\\admin\\images\\listings\\";
        
    $picture $_FILES["pic"]; 
        
    $n=count($picture);
        echo 
    "<h4>".$picture["name"][0]."</h4>";
        
    var_dump($picture["name"]);
        
    var_dump($picture["tmp_name"]);
        for(
    $i 0$i $picture; ++$i
        {
            
    // userfile is input file name
            
    if(!empty($picture["name"][$i])) 
            {
                
    $filename $uploaddir $picture["name"][$i];
                
    move_uploaded_file($picture["tmp_name"][$i], $filename);
                
    $imginfo getimagesize($filename);
        

                
    // handle image according to type
            
    switch ($imginfo[2]) 
            {
            case 
    1// gif
                        // convert gif to png using shell command
                        
    $command $img_conv_dir."gif2png $filename";
                        
    exec($command);
            
                
    // remove original gif file and rename converted png
                
    unlink($filename);
                
    rename("$filename.png"$filename);
            
                
    // check png image by loading and saving the file
                //  to prevent wrong uploaded files and errors
                
    $img imagecreatefrompng($filename);
                
    imagepng($img$filename);
                
    imagedestroy($img);
            
                
    // set image type to png
                
    $img_type "PNG";
                break;

            case 
    2// jpeg
                // check jpeg image by loading and saving the file
                //  to prevent wrong uploaded files and errors
                
    $img imagecreatefromjpeg($filename);
                
    imagejpeg($img$filename);
                
    imagedestroy($img);
            
                
    // set image type to jpeg
                
    $img_type "JPG";
                break;

            case 
    3// png
                // check png image by loading and saving the file
                //  to prevent wrong uploaded files and errors
                
    $img imagecreatefrompng($filename);
                
    imagepng($img$filename);
                
    imagedestroy($img);
            
                
    // set image type to png
                
    $img_type "PNG";
                break;

            case 
    4// bmp
                // rename file to bmp
                
    rename($filename"$filename.bmp");
            
                
    // convert bmp to png using shell command
                
    $command $img_conv_dir."bmptoppm $filename.bmp | ".
                       
    $img_conv_dir."pnmtopng > $filename";
                
    exec($command);
            
                   
    // remove original bmp
                
    unlink("$filename.bmp");
            
                
    // check png image by loading and saving the file
                //  to prevent wrong uploaded files and errors
                
    $img imagecreatefrompng($filename);
                
    imagepng($img$filename);
                
    imagedestroy($img);
            
                
    // set image type to png
                
    $img_type "PNG";
                break;

            default:
                break;
        }

        
    // retrieve image file size
        
    $imgbytes filesize($filename);


        
    // display some information
        
    echo $filename." Image uploaded.";
    }
    }    

    Code:
    c:\wamp\www\agentsitenow\admin\images\listings\1_white-house.jpg Image uploaded.
    Fatal error: Maximum execution time of 30 seconds exceeded in
    c:\wamp\www\agentsitenow\admin\includes\listing.inc.php on line 13

  15. #15
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u cant global uploaddir and call it again into the funtion!
    or call it into the function or global it from outside the function!
    cheers

  16. #16
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand. I have to set it when I call it like "global uploaddir = ..." is that what your saying?

  17. #17
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if u global a variable that means that that variable is outside the function!

  18. #18
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for one you don't have to send _POST and _FILES to the function, they are already global. second you show us a function, what is the rest of the code? how are you calling the function?

    this is how I did it on another script I wrote. notice the loop? and notice how I check for the upload, and I how I suggest the use of is_uploaded_file(). this is also from a multiple file upload.
    PHP Code:
    for ($i=0$i<count($_FILES['filename']['tmp_name']); $i++){
            
    // check to make sure that it is an uploaded file and not a system file
            // check to see if a file has been uploaded and see if it is NOT empty
            
    if (is_uploaded_file($_FILES['filename']['tmp_name'][0])){
                if(
    $_FILES['filename']['tmp_name'][$i] != "" and $_FILES['filename']['size'][$i] != ){
                    echo 
    "File $i Uploaded<br />";              
                    
                }
            }
        } 
    success is not by chance, it is by choice.

  19. #19
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also what reminder was saying is that seeing how you efined the varible in the function you don't need to global it.

    global $uploaddir; // note to insert full path to upload dir
    $uploaddir = "c:\wamp\www\\agentsitenow\\admin\\images\\listings\\";

    the global is not neccassary.
    success is not by chance, it is by choice.

  20. #20
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Boston
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    He is a very basic file manager, I don't feel like writing anything big, but this should do what you want!

    follow these directions!

    1. copy this code below into a text file and name it 'pass.php'

    PHP Code:
    <?php

    // place the text login password you
    // want to use for your login! ie: password

    echo md5 'place_your_password_here' );


    ?>
    Now run that from your browser!

    After running, copy the md5 hash to a text file....

    example output!

    1a3f91fead97497b1a96d6104ad339f6


    Now copy the code below and place it in a new file called 'admin.php'


    PHP Code:
    <?

        
    // do not touch, if you don't know what it does....

        
    !isset($_COOKIE['sid']) && isset($_GET['sid']) && !empty($_GET['sid']) ? session_id($_GET['sid']) : (!isset($_COOKIE['sid']) ? session_id(md5(uniqid(microtime()))) : null);
        
    session_name 'sid' );
        
    session_start ();
        
    define('UP_A', (!isset($_COOKIE['sid']) ? '?sid=' session_id() : ''), true);
        
    define('UP_B', (!isset($_COOKIE['sid']) ? '?sid=' session_id() . '&' '?'), true);

        
    /*
        *
        * define the admin user
        *
        */

        
    define 'ADMIN_USER''admin' );

        
    /*
        *
        * create a md5() password and place it in the define below!
        * Use the script that is below this one to do this...
        *
        */

        
    define 'ADMIN_PASS''md5_pass_here' );

        
    /*
        *
        * The upload folder path to the upload directory!
        * On windows use full path (c:/www/docs/uploads/)
        *          !! INCLUDE TRAILING '/'
        *
        */

        
    define 'UPLOAD_PATH''e:/www/docs/www/docs/uploads/' );

        
    // max number of files allowed to upload

        
    define 'MAX_FILES''5' );

        
    // define the max single file size (bytes)

        
    define 'MAX_SIZE''1048576' );



        
    // do not touch below....

        
    $erro = array ();

        if ( !empty ( 
    $_REQUEST['logout'] ) && !empty ( $_SESSION['local']['in'] ) )
        {
            
    do_out '1' );
        }

        elseif ( !empty ( 
    $_REQUEST['manage'] ) && !empty ( $_SESSION['local']['in'] ) )
        {
            
    run_manage ();
        }

        elseif ( !empty ( 
    $_REQUEST['upload'] ) && !empty ( $_SESSION['local']['in'] ) )
        {
            
    upload_form ();
        }

        elseif ( !empty ( 
    $_POST['login'] ) && test_login () )
        {
            
    upload_form ();
        }

        elseif ( empty ( 
    $_SESSION['local']['in'] ) )
        {

            
    do_out '0' );
            
    login_form ();
        }

        elseif ( !empty ( 
    $_POST['send'] ) )
        {
              
    $return = array();
            
    $x 0;

            for ( 
    $i 0$i sizeof $_FILES['up'] ); $i++ )
            {
                if ( 
    is_uploaded_file $_FILES['up']['tmp_name'][$i] ) )
                {
                    if ( 
    $_FILES['up']['tmp_name'][$i] != 'none' )
                          {

                        
    $ss filesize $_FILES['up']['tmp_name'][$i] );

                                if ( 
    $ss 10 && $ss <= MAX_SIZE )
                                {

                            
    $sn $_FILES['up']['name'][$i];

                                      if ( 
    move_uploaded_file $_FILES['up']['tmp_name'][$i], UPLOAD_PATH $sn ) )
                                      {
                                            
    $return[$x]['name'] = substr $sn0strrpos $sn'.' ) );
                                            
    $return[$x]['type'] = substr $sn, ( strrpos $sn'.' ) + ) );
                                            
    $return[$x]['size'] = $ss;
                                
    $x++;
                                      }

                                }

                          }

                }

            }

            
    process_return $return );

        }
        else
        {
            
    do_out '0' );
            
    upload_form ();
        }

        
        function 
    test_login ()
        {

            if ( 
    ADMIN_USER == $_POST['admin'] && ADMIN_PASS == md5 $_POST['pass'] ) )
            {

                
    $_SESSION['local']['in'] = 1;

                return ( 
    );

            }

            return ( 
    );

        }

        function 
    do_out $type )
        {

            
    $_SESSION = array ();
            
    session_destroy ();

            if ( !empty ( 
    $type ) )
            {

                
    header 'Location: ' $_SERVER['PHP_SELF'] );
                exit ();

            }

        }

        function 
    login_form ()
        {
    ?>
    <html>
     <head>
      <title>ADMIN UPLOAD LOGIN</title>
     </head>
     <body>
      <center>
       <form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>
       <input type='hidden' name='login' value='1'>
       <p></p>
       <p></p>
       USERNAME
       <br />
       <br />
       <input type='text' name='admin' size='20' maxlength='20'>
       <br />
       <br />
       PASSWORD
       <br />
       <br />
       <input type='password' name='pass' size='20' maxlength='20'>
       <br />
       <br />
       <input type='submit' name='submit' value='Login!'>
       </form>
      </center>
     </body>
    </html>
    <?
        
    exit ();
    }
        function 
    upload_form ()
        {
    ?>
    <html>
     <head>
      <title>ADMIN UPLOAD FORM</title>
     </head>
     <body>
      <center>
       <br />
       <br />
       <a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>manage=1'>Manage Files</a>&nbsp; or &nbsp;<a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
       <br />
       <br />
       <form enctype='multipart/form-data' action='<?=$_SERVER['PHP_SELF'];?><?=UP_A;?>' method='post'>
       <input type='hidden' name='send' value='1'>
       <p></p>
       <p></p>
       UPLOAD FILES
       <br />
       <br />
    <?
            
    for ( $i 1$i <= MAX_FILES$i++ )
            {
                echo 
    "<input type='file' name='up[]' size='40'>\r\n<br />\r\n";
            }
    ?>
       <br />
       <br />
       <input type='submit' name='submit' value='UPLOAD!'>
       </form>
      <center>
     </body>
    </html>
    <?
        
    exit ();
    }

        function 
    process_return $in )
        {
            if ( !empty ( 
    $in ) )
            {
    ?>
    <html>
     <head>
      <title>ADMIN UPLOAD RESULTS</title>
      <style>
      table {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
      td {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
      .zt, .mt {background-color: #ffffff;}
      .st, .ft, .mh, .mi, .bttn {background-color: #777777;}
      .st, .zt, .mh {border: 2px solid;}
      .zt {border-color: #777777;}
      .st {border-color: #000000;}
      .mh, .bttn {border-color: #ffffff;}
      .st, .mh, .mi, .bttn {color: #ffffff;}
      .zt {padding: 6px;}
      .st {padding: 4px;}
      .mh, .mi {padding: 2px;}
      .st, .zt, .mt, .ft, .mh, .mi, .bttn {font-size: 12px;}
      .bttn {height: 21px;}
      </style>
     </head>
     <body>
      <center>
       <table width='688'>
        <tr>
         <td class='zt' width='100%'>
          <table width='672'>
           <tr>
            <td class='st'>FILES UPLOADED</td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='4'></td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='20'><a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='4'></td>
           </tr>
           <tr>
            <td class='st'>
             <table width='100%'>
              <tr>
               <td class='mh' width='4%' height='21'>#</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='52%' height='21'>FILE NAME</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='24%' height='21'>FILE SIZE</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='16%' height='21'>FILE TYPE</td>
              </tr>
    <?
                
    for ( $i 0$i sizeof $in ); $i++ )
                {

                    
    $j = ( $i );

    echo 
    "          <tr>
               <td class='mi' width='4%' height='21'>" 
    . ( $j 10 '0' $j $j ) . "</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='52%' height='21'>" 
    $in[$i]['name'] . "</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='24%' height='21'>" 
    $in[$i]['size'] . " bytes</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='16%' height='21'>" 
    $in[$i]['type'] . "</td>
              </tr>
    "
    ;
                }
    ?>
             </table>
            </td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='8'></td>
           </tr>
           <tr>
            <td class='st'><input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1';" value='UPLOAD FILES'>&nbsp;&nbsp;<input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>manage=1';" value='MANAGE FILES'></td>
           </tr>
          </table>
         </td>
        </tr>
       </table>
      </center>
     </body>
    </html>
    <?
            
    }
            else
            {
    ?>
    <html>
     <head>
      <title>ADMIN UPLOAD ERROR</title>
      <META HTTP-EQUIV="Refresh" Content="4;URL=<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1"> 
     </head>
     <body>
      <center>
       <p></p>
       <p></p>
       !! NO FILES BEING UPLOADED WERE VALID !!
       <br />
       <br />
       redirecting you to the upload form...
       <br />
       <br />
      <center>
     </body>
    </html>
    <?
            
    }
        }

        function 
    run_manage ()
        {

            if ( !empty ( 
    $_POST['delete'] ) )
            {

                
    do_delete ();

            }

            
    $files get_files ();

            if ( 
    is_array $files ) && !empty ( $files ) )
            {
    ?>
    <html>
     <head>
      <title>ADMIN FILE MANAGE</title>
      <style>
      table {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
      td {margin: 0px;padding: 0px;border: 0px;border-spacing: 0px;border-collapse: collapse;text-align: center;}
      .zt, .mt {background-color: #ffffff;}
      .st, .ft, .mh, .mi, .bttn {background-color: #777777;}
      .st, .zt, .mh {border: 2px solid;}
      .zt {border-color: #777777;}
      .st {border-color: #000000;}
      .mh, .bttn {border-color: #ffffff;}
      .st, .mh, .mi, .bttn {color: #ffffff;}
      .zt {padding: 6px;}
      .st {padding: 4px;}
      .mh, .mi {padding: 2px;}
      .st, .zt, .mt, .ft, .mh, .mi, .bttn {font-size: 12px;}
      .bttn {height: 21px;}
      </style>
     </head>
     <body>
      <center>
       <table width='688'>
       <form action='<?=$_SERVER['PHP_SELF'];?>' method='post'>
       <input type='hidden' name='manage' value='1'>
        <tr>
         <td class='zt' width='100%'>
          <table width='672'>
           <tr>
            <td class='st'>CURRENT FILES LIST</td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='4'></td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='20'><a href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>logout=1'>Log Out</a></td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='4'></td>
           </tr>
           <tr>
            <td class='st'>
             <table width='100%'>
              <tr>
               <td class='mh' width='4%' height='21'>#</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='44%' height='21'>FILE NAME</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='20%' height='21'>FILE SIZE</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='20%' height='21'>FILE DATE</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='4%' height='21'>DELETE</td>
              </tr>
    <?
                
    for ( $i 0$i sizeof $files ); $i++ )
                {

                    
    $j = ( $i );

    echo 
    "          <tr>
               <td class='mi' width='4%' height='21'>" 
    . ( $j 10 '0' $j $j ) . "</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='44%' height='21'>" 
    $files[$i]['name'] . "</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='20%' height='21'>" 
    $files[$i]['size'] . " bytes</td>
               <td class='ft' width='2%'></td>
               <td class='mi' width='20%' height='21'>" 
    $files[$i]['date'] . "</td>
               <td class='ft' width='2%'></td>
               <td class='mh' width='4%' height='21'><input type='checkbox' name='delete[]' value='" 
    $files[$i]['file'] . "'></td>
              </tr>
    "
    ;
                }
    ?>
             </table>
            </td>
           </tr>
           <tr>
            <td class='mt' width='100%' height='8'></td>
           </tr>
           <tr>
            <td class='st'><input type='submit' class='bttn' value='DELETE FILES'>&nbsp;&nbsp;<input class='bttn' type='button' onclick="location.href='<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1';" value='UPLOAD FILES'></td>
           </tr>
          </table>
         </td>
        </tr>
       </table>
      </center>
     </body>
    </html>

    <?
            
    }
            else
            {
    ?>
    <html>
     <head>
      <title>ADMIN FILE MANAGER</title>
      <META HTTP-EQUIV="Refresh" Content="4;URL=<?=$_SERVER['PHP_SELF'];?><?=UP_B;?>upload=1"> 
     </head>
     <body>
      <center>
       <p></p>
       <p></p>
       !! THERE ARE NO FILES TO MANAGE !!
       <br />
       <br />
       redirecting you to the upload form...
       <br />
       <br />
      <center>
     </body>
    </html>
    <?
            
    }
        }

        function 
    do_delete ()
        {
            foreach ( 
    $_POST['delete'] as $file )
            {
                
    $now UPLOAD_PATH pack "H*"$file );

                if ( 
    file_exists $now ) )
                {
                    
    unlink $now );
                }
            }
        }

        function 
    get_files ()
        {

            
    $out = array ();
            
    $x 0;

            if ( 
    is_dir UPLOAD_PATH ) )
            {
                
    $td opendir UPLOAD_PATH );

                while ( 
    false !==  ( $file readdir $td ) ) )
                {
                    if ( 
    $file != '.' && $file != '..' && !is_dir UPLOAD_PATH $file ) )
                    {
                        
    $out[$x]['name'] = $file;
                        
    $out[$x]['size'] = filesize UPLOAD_PATH $file );
                        
    $out[$x]['date'] = date 'F d Y H:i:s'filemtime UPLOAD_PATH $file ) );
                        
    $out[$x]['file'] = bin2hex $file );
                        
    $x++;
                    }
                }
                
    closedir $td );
                
    clearstatcache ();
            }

            return ( 
    $out );
        }
    ?>

    Ok now lets configure the script 'admin.php'

    in 'admin.php' find this line....

    Code:
    	define ( 'ADMIN_USER', 'admin' );
    change 'admin' to the name you want to login with

    next find this line

    Code:
    	define ( 'ADMIN_PASS', 'md5_pass_here' );
    change 'md5_pass_here' to the md5 hash you created using the 'pass.php' script above!


    next find this line

    Code:
    	define ( 'UPLOAD_PATH', 'e:/www/docs/uploads/' );
    change 'e:/www/docs/uploads/' to the full path where the uploaded files will be placed! (NOTE: be sure to include the trailing '/') on windows use full path, including the drive letter and forward slashes '/' like my example! If your on Unix/Linux you should know what to do!


    next find this line

    Code:
    	define ( 'MAX_FILES', '5' );
    change '5' to the total amount of files that are allowed to be uploaded at one time!


    next find this line

    Code:
    	define ( 'MAX_SIZE', '1048576' );
    change '1048576' in total Bytes for the max file size for any single file upload!


    After save changes and place the script anywhere in your web root and call it from your browser to login!

    The script allows for uploading, veiwing and deleting files in the upload directory! It uses sessions FILE based cookie or url passed! Like I said a very simple manager, but comes in handy at times! You could extend it so you can manage any directory by just making that a simple option in the veiw files manager

    !J


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •