...

View Full Version : tar open and copy error



thesavior
04-27-2006, 03:46 AM
I am trying to open a tar, and copy the files into the main directory.

this is my 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'] > 0 && 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?

GJay
04-27-2006, 08:19 AM
tars are binary files, so you can't just 'read' them. Using exec with:
tar -xf name.tar

can extract it for you

thesavior
04-28-2006, 02:12 AM
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.

Nightfire
04-28-2006, 03:54 AM
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

thesavior
04-28-2006, 04:00 AM
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.

thesavior
04-29-2006, 12:43 AM
*bump*

thesavior
04-30-2006, 09:04 PM
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?

thesavior
05-02-2006, 01:30 AM
*bump*

thesavior
05-03-2006, 12:55 AM
*bump*

missing-score
05-03-2006, 08:27 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum