1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP ME] Tiny PHP problem is "ruining my life"!

Discussion in 'PHP & Perl' started by drnobrain, Dec 2, 2010.

  1. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Hi everybody,

    First of all, thanks in advance even if you only take your time to read this post.

    Today I wanted to start my coaching services upsell. I uploaded a PHP script, Ji*m*my D. Bro*wn's Easy Co*ach Pro. Translated everything from English to my language in the script. Took a few days.

    Although I'm a TOTAL IDIOT to PHP, I exactly figured out what parts can I owerwrite, and what not. So, translated everything, then

    EVERYTHING WORKS LIKE A CHARM, BUT...

    ... but the freakin' upload part!

    If a member, or me, the admin try to upload something, it should create a new directory in the "data" folder, and move the freshly uploaded file over there.

    Anyhow I try (for example, from member side) this error message comes:

    PHP:
    Warningmove_uploaded_file(./data/19/) [function.move-uploaded-file]: failed to open streamIs a directory in /chroot/home/visszasz/joyridercoaching.com/html/incs/front/inc/uploadedit.inc.php on line 45

    Warning
    move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpQOE2AK' to './data/19/' in /chroot/home/visszasz/joyridercoaching.com/html/incs/front/inc/uploadedit.inc.php on line 45
    It refers to this part of the script:

    PHP:
        }else{
         
    move_uploaded_file($NEWFILE,"./data/$curmember[mid]/$NEWFILE_name");
         if(!
    is_file($curfile)){
          
    $errorflag true;
          
    $msg alert("Akadt némi probléma a fájl feltöltése közben...");
         }
    I don't think it's permission issue, data folder has 777 attributes. (And any of its subdirs, if created.)

    Here's the full uploadedit.inc.php, if needed:


    PHP:
    <?php

     
    if($MemberOK){
      
    $tpl->define( array(
       
    'uploadedit' => "./incs/front/templates/uploadedit.tpl"
      
    ));

      
    $msg "";
      
    $id prepare_data($id);
      if(!
    $Submit){
       
    $formheader "Új Feltöltés";
       
    $tpl->assign( array (
        
    "FORMHEADER" => $formheader,
        
    "MSG" => $msg,
        
    "HIDFILE" => "",
        
    "TITLE" => "",
        
    "FILENAME" => "",
        
    "FILESIZE" => ""
       
    ));
      }else{
       
    $errorflag false;
       
    $uploaded true;
       if(!
    is_uploaded_file($NEWFILE)){
        
    $uploaded false;
       }else{
        if(!
    is_dir("./data/$curmember[mid]")){
         @
    mkdir("./data/$curmember[mid]",0777);
        }
        
    $curfile "./data/$curmember[mid]/$NEWFILE_name";
        
    $curfilename $NEWFILE_name;
        
    $curfiletype $NEWFILE_type;
       }

       
    $TITLE prepare_data($TITLE);
       
    $tmpcntdup DB_count_uploads($DB,"where title='$TITLE' and mid='$curmember[mid]'");
       
    $created time();
       if(
    $uploaded){
        
    $id DB_getmaxuploadid($DB) + 1;
        
    $DBRES $DB->query("select SUM(filesize) from mb_uploads where mid='$curmember[mid]' and admin='0'");
        
    $DBROW $DBRES->fetch_assoc();
        if(
    $DBROW[0] >= $UPLOAD_SPACE){
         
    $errorflag true;
         
    $msg alert("Túllépted a feltöltési keretet(25Mb)");
        }else{
         
    move_uploaded_file($NEWFILE,"./data/$curmember[mid]/$NEWFILE_name");
         if(!
    is_file($curfile)){
          
    $errorflag true;
          
    $msg alert("Akadt némi probléma a fájl feltöltése közben...");
         }
         
    $curfilesize = @filesize($curfile);
         
    $formheader "Új Feltöltés";
         
    $query "insert into mb_uploads (id,mid,title,filename,filesize,filetype,created,admin) values
                   ('
    $id','$curmember[mid]','$TITLE','$curfilename','$curfilesize','$curfiletype','$created','0')";
         if(
    $tmpcntdup != 0){
          
    $errorflag true;
          
    $msg alert("Van már ilyen elnevezés&#369; feltöltés. Kérlek, próbáld újra.");
         }
        }
       }else{
        
    $errorflag true;
        
    $msg alert("Akadt némi probléma a fájl feltöltése közben...");
       }
       if(!
    $errorflag){
        
    $DB->query($query);
        if(
    $DB->error()){
          
    $msg alert("Nem tudtam frissíteni az információt.");
        }else{
          
    $msg alert("Az információt sikeresen frissítettem. Most már láthatod a feltöltések listáján."12'blue');
          
    header("Location: $SCRIPTURL/index.php?cmd=uploads");
        }
       }
       
    $formheader "Új Feltöltés";
       
    $tpl->assign( array (
        
    "FORMHEADER" => $formheader,
        
    "MSG" => $msg,
        
    "HIDFILE" => "",
        
    "TITLE" => "$TITLE",
        
    "FILENAME" => "",
        
    "FILESIZE" => ""
       
    ));

      }

      
    $tpl->assign("MNAME""$curmember[firstname] $curmember[lastname]");
      
    $tpl->assign"ACTION""$SCRIPTURL/index.php?cmd=uploadedit");

      
    $tpl->parse("INDEX_CONTENT""uploadedit");
     }else{
      
    header("Location: $SCRIPTURL/index.php?cmd=login");
     }

    ?>
    Please help, I know it would be a kid's play to a PHP guy.

    Thanks in advance,

    Doc
     
  2. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Is the the temp file there (/tmp/phpQOE2AK)? Try setting the absolute path of your data folder and see what happens.
    PHP:
    move_uploaded_file($NEWFILE,"./data/$curmember[mid]/$NEWFILE_name"); 
    to
    PHP:
    move_uploaded_file($NEWFILE,"/absolute/path/to/data/$curmember[mid]/$NEWFILE_name"); 
     
    • Thanks Thanks x 1
  3. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Whooops, double post, sorry. Read below:
     
    Last edited: Dec 2, 2010
  4. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Grizzy, what do you exactly mean under "absolute path"? According to my error message would it be:

    Code:
    /chroot/home/visszasz/joyridercoaching.com/html/data/$curmember[mid]/$NEWFILE_name
    ?
     
  5. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Well, obviously you were thinking about something else, because I tried the path above, and it still doesn't work... :S
     
  6. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Made fast internet search, saw an example of absolute path.

    "chroot/" deleted, starts with "/home..."

    Still doesn't work, same error message, but with this longer "seemed-to-be-absolute-path" in the first line instead of "./data..."
     
  7. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Ok. New search for absolutepath.

    Got a code:

    PHP:
    <?php echo $_SERVER['DOCUMENT_ROOT']; ?>
    Saved a s absolutepath.php, uploaded to root, loaded with firefox, it shows my absolute path:

    Code:
    /home/visszasz/joyridercoaching.com/html
    Okay, modified my script:
    PHP:
    move_uploaded_file($NEWFILE,"/home/visszasz/joyridercoaching.com/html/data/$curmember[mid]/$NEWFILE_name");
    AND FREAKIN' ERROR COMES :banghead:

    PHP:
    Warningmove_uploaded_file(/home/visszasz/joyridercoaching.com/html/data/19/) [function.move-uploaded-file]: failed to open streamIs a directory in /chroot/home/visszasz/joyridercoaching.com/html/incs/front/inc/uploadedit.inc.php on line 45

    Warning
    move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqZeu4z' to '/home/visszasz/joyridercoaching.com/html/data/19/' in /chroot/home/visszasz/joyridercoaching.com/html/incs/front/inc/uploadedit.inc.php on line 45
    I really dunno what the heck shall I try, and this tiny littl' sh*t delays my work... :(
     
  8. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Sorry man, I can't do much debugging from here. But that error means that the move_uploaded_file() function is expecting one of its parameters to be a path to a file and it's finding a directory there instead. It's got to be some sort of error realted to the path. I guess it could be permission related, but I would think the error would be different.. :confused:
     
    • Thanks Thanks x 1
  9. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Okay, at least you tried your best to help, I do very appreciate it. Now I continue to search for the root of the problem.

    Again: thanks for your valuable time, Grizzy!
     
  10. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Your welcome drnobrain :). I'm sure a much more knowledgeable php coder will come along soon with some advice. Good luck!
     
  11. risefromdeath

    risefromdeath Power Member

    Joined:
    Jul 1, 2009
    Messages:
    650
    Likes Received:
    107
    Clearly its a path issue from what i can get of this limited info over here..this should solve the issue

    PHP:
    <?PHP
    $tmpfile 
    tempnam("dummy","");
    $path dirname($tmpfile);
    echo 
    $path;
    unlink($tmpfile);
    ?> 
    upload this file to your server this will give the path to temporary directory

    now store that value in a variable and append the path to the temporary file name..
    Thats should solve it
     
    • Thanks Thanks x 1
  12. showboytridin

    showboytridin Regular Member

    Joined:
    Sep 5, 2009
    Messages:
    348
    Likes Received:
    714
    Location:
    127.0.0.1
    Your $NEWFILE_name seems empty. echo your $NEWFILE_name to see the results.
     
    • Thanks Thanks x 1
  13. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Thanks for caring about me, but as I mentioned in my first post in this thread, I'm an (aaaaalmost) TOTAL IDIOT to PHP.

    So the things that you suggested are "completely Chinese" to me. :) :(

    I don't know how exactly apply this value to the script I attached to thread starter. What I understood is to make a php file containing this code you provided.

    Okay, made a temp.php, uploaded to root, and that's it. I don't know what to do next. :(
     
  14. drnobrain

    drnobrain Registered Member

    Joined:
    Dec 12, 2008
    Messages:
    99
    Likes Received:
    129
    Thanks for your time, but I really don't know what this means and how to solve it. :(
     
  15. senators24

    senators24 Newbie

    Joined:
    Dec 14, 2010
    Messages:
    13
    Likes Received:
    1
    yeah, that is pretty bad