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 10 of 10
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    tar open and copy error

    I am trying to open a tar, and copy the files into the main directory.

    this is my code:

    PHP Code:
    <?php
    $file
    ['size'] = $_FILES['style_package']['size'];
        
    $file['error'] = $_FILES['style_package']['error'];
        
    $file['name'] = $_FILES['style_package']['name'];
        
    $file['tmp_name'] = $_FILES['style_package']['tmp_name'];
            if(
    substr($file['name'], -4) == '.php' && $cur_project['PowerBBmod'] == 0$file['name'] .= 's';
            switch (
    $file['error'])
            {
                case 
    1:
                case 
    2:
                    
    $errors[] = $file['name'].': Too large ini';
                    break;
                case 
    3:
                    
    $errors[] = $file['name'].': Partial upload';
                    break;
            }
            if(
    $file['size'] > && empty($errors))
            {
                
    $filename $file['tmp_name'];
                
    $fp fopen($filename,"rb");
                
    $tar_file fread($fp,filesize($filename));
                
    fclose($fp);
                
    $tar_length strlen($tar_file);
                
    $main_offset 0;
                
    $outbuffer '';
                
    $error 0;
                
    $lastdir '';
                while(
    $main_offset $tar_length)
                {
                    if(
    substr($tar_file,$main_offset,512) == str_repeat(chr(0),512)) break;
                    
    $position        strpos(substr($tar_file,$main_offset,100),chr(0));
                    
    $filename        substr(substr($tar_file,$main_offset,100),0,$position);
                    
    $filesize        octdec(substr($tar_file,$main_offset 124,12));
                    
    $filecontents    substr($tar_file,$main_offset 512,$filesize);
                    if(
    $filesize 0)
                    {
                        if(
    is_file($filename))
                        {
                            
    $outbuffer .= "\t\t\t\t\t".'<li><strong>File already existed:</strong> '.$filename.' - Not unpacked</li>'."\n";
                            
    $error 1;
                        }
                        else
                        {
                            
    $f fopen($filename'w');
                            
    fwrite($f$filecontents);
                            
    fclose($f);
                            
    $outbuffer .= "\t\t\t\t\t".'<li>Unpacked file: '.$filename.'</li>'."\n";
                        }
                    }
                    else
                    {
                        
    $dirs explode('/'$filename);
                        foreach(
    $dirs as $dir)
                        {
                            
    $cdir $lastdir.$dir;
                            if(@
    mkdir($cdir))
                            {
                                
    $outbuffer .= "\t\t\t\t\t".'<li>Created directory: '.$filename.'</li>'."\n";
                                
    $f fopen($filename.'/index.html''w');
                                
    fwrite($f"<html>\n<head>\n<title>.</title>\n</head>\n<body>\n.\n</body>\n</html>");
                                
    fclose($f);
                            }
                            
    $lastdir $cdir.'/';
                        }
                        
    $lastdir '';
                    }
                    
    $main_offset += 512 + (ceil($filesize 512) * 512);
    ?>
    and these are the errors im getting:
    Warning: fopen(img/Night/adminmenu.png) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/b.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/bg.png) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/cat_center.jpg) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/center.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/code.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/color.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/h.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/headerbg.png) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/header_forums2.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/header_forums3.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/hr.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/i.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/img.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/index.html) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/is.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59

    Warning: fwrite(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 60

    Warning: fclose(): supplied argument is not a valid stream resource in /raid5/home/eli/public_html/forum/admin_themes.php on line 61

    Warning: fopen(img/Night/left.gif) [function.fopen]: failed to open stream: No such file or directory in /raid5/home/eli/public_html/forum/admin_themes.php on line 59
    and the list goes on and on. What I am thinking, is that it isn't reading the tar, it is trying to read something else. I could be wrong, but can someone take a look at this?

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    tars are binary files, so you can't just 'read' them. Using exec with:
    tar -xf name.tar

    can extract it for you

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    can i get an example of the actual code to do it? Can you edit my posted script to add that? Im not familiar with exec, how to use it, or where to put it, and i don't have time to go and learn it on php.net.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    A quick fix isn't advisable. Why not read about exec on php.net? You will then be familier of it, when to use it, where to use it, etc etc. Laziness doesn't get you far

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    It seems like 2 or 3 lines that need to be added to my script, it would be really helpful if someone could just edit my script accordingly, but if not, then i will get to it when i get a chance. Sorry for sounding demanding and saying that im not going to do my work. lol Not how I mean this to sound.

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    What if i do this with a .gz? Can someone help me out with all of the zlib functions and using them to do this?
    Last edited by thesavior; 04-30-2006 at 10:10 PM.

  • #8
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #9
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #10
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you need to search google... When you bump 5 times and no-one replies it means either:

    • You are not trying
    • No-one knows the answer


  •  

    Posting Permissions

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