Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help making 2 thing happen

    Hi, I got form that let you state a folder name, on sumbit thw script creates the folder with the name you stated, the problem is I want it to upload the php file "view.php" when the folder is created, I think I set the value wrong but can get it to work

    original script

    PHP Code:
    Code: ( php )
    <?php
    #include ("mymail.php");
    $folder $_POST['folder'];
    ?>
    <?php
    mkdir
    ("$folder"0777);
    ?> 

    <!doctype html public "-//w3c//dtd html 3.2//en">
     
    <html>
     
    <head>
    <title>Mardos/title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    </head>
     
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
        
    while(list($key,$value) = each($_FILES[images][name]))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                    
                        
    $add "$folder/$filename";
                        
                           
    //echo $_FILES[images][type][$key];
                     // echo "<br>";
                        
    copy($_FILES[images][tmp_name][$key], $add);
                        
    chmod("$add",0777);
                
     
                }
            }
     
     
    ?>
     
     
    </body>
     
    </html>

    My first try

    PHP Code:
    Code: ( php )
    <?php
    #include ("mymail.php");
    $folder $_POST['folder'];
    ?>
    <?php
    mkdir
    ("$folder"0777);
    ?> 

    <!doctype html public "-//w3c//dtd html 3.2//en">
     
    <html>
     
    <head>
    <title>Mardos/title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    </head>
     
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
        
    while(list($key,$value) = each($_FILES[images][name]))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                    
    $add"$folder/view.php";
                        
    $add. = "$folder/$filename";
    # I also tried it without the dot
                        
                           //echo $_FILES[images][type][$key];
                     // echo "<br>";
                        
    copy($_FILES[images][tmp_name][$key], $add);
                        
    chmod("$add",0777);
                
     
                }
            }
     
     
    ?>
     
     
    </body>
     
    </html>
    my second try

    PHP Code:

    Code: ( php )
    <?php
    #include ("mymail.php");
    $folder $_POST['folder'];
    ?>
    <?php
    mkdir
    ("$folder"0777);
    ?> 

    <!doctype html public "-//w3c//dtd html 3.2//en">
     
    <html>
     
    <head>
    <title>Mardos/title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    </head>
     
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
        
    while(list($key,$value) = each($_FILES[images][name]))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                    
    $view"$folder/view.php";
                        
    $add "$folder/$filename";
                        
                           
    //echo $_FILES[images][type][$key];
                     // echo "<br>";
                        
    copy($_FILES[images][tmp_name][$key], $add$view);
                        
    chmod("$add",0777);
                
     
                }
            }
     
     
    ?>
     
     
    </body>
     
    </html>
    Last edited by webandwe; 06-05-2007 at 02:27 PM.

  • #2
    New Coder
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I had to read your post at least 4 times to understand what the question was, please be more specific about your actual goals next time; "I would like to alter this script so that it not only uploads a file to a given directory, but also copies over my view.php script into that directory".

    Where is this view.php file? You're not "uploading" view.php as you claim, so where on the webserver is it?

    Personally I'd rewrite it like this;
    PHP Code:
    if(!empty($value)) {
      
    $add sprintf('%s/%s'escapeshellarg($folder), escapeshellarg($value));
      
    $view sprintf('%s/view.php'escapeshellarg($folder));

      
    copy($_FILES[images][tmp_name][$key], $add);
      
    copy('/location/of/view.php'$view);

      
    chmod($add0644);
      
    chmod($view0755);

    Note that I altered the chmod commands; 0644 should be fine for any uploaded file (it makes it read/write for the owner, and read-only for anyone else), and 0755 for an executable script (read/write/execute for owner, read/execute for anyone else). If this is unsatisfactory try 0775 and 0664, but 0777 is read/write/execute for anyone, which is a security hole.

    I'd also move that '/location/of/view.php' to a define() somewhere in the header of your script;
    PHP Code:
    define('VIEW_SCRIPT_LOCATION''/location/of/view.php'); 
    and then refer to the script with the constant VIEW_SCRIPT_LOCATION in my above code.

    Even better, if you're using a Linux host, would be to use symbolic links instead of making loads of copies of view.php -- just link to its location instead, that way when you update view.php later you'll have updated ALL 'copies' in one go; replace the copy() of view.php with something like
    PHP Code:
    symlink($view'/location/of/view.php'); 
    Again, this would be neater if you used the VIEW_SCRIPT_LOCATION constant.

    I can't help but think that your whole architecture could do with reworking, the way you're doing it now is a bit nasty You're also not checking for errors of any kind, which will no doubt bring you back later wondering why it won't work.

    PS. just in case you're unaware; 755 is a decimal integer, whereas 0755 is an octal integer (the leading 0 denotes this in PHP).

    I hope that helps anyway
    Every PHP programmer of any skill level should set error_reporting(E_ALL); at the top of their scripts or in their php.ini

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Man,

    Sorry for my bad English, I try to explain better next time.

    That script you gave me did not quite work as it should, I guess it does not work well with the previous page that runs before it.

    However I managed to use your coding and got it working...

    Thank you for your response and coding help!!!

    Regards,


  •  

    Posting Permissions

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