What variable do I have to destroy to make this work correctly?

by meriad
5 replies
I am trying to create a script that will automatically update my website using Share-a-sale datafeeds. I've got most of it figured out, but can't seem to figure out a bug in the script I wrote.

so far I have this for my code:
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
set_time_limit(2400);

echo date('M d');
echo "<br>";

//$ftp_server = "xxxxx";
//$ftp_user = "xxxxx";
//$ftp_pass = "xxxx";
//$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

//if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
// echo "Connected as $ftp_user@$ftp_server\n";
//} else {
// echo "Couldn't connect as $ftp_user\n";
//}

echo "<br>";

echo "here";
echo "<br>";

function rawlist_dirdump() {
$ftp_server = "xxxxxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxx";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_user\n";
}

// global $conn_id;
$ftp_rawlist = ftp_rawlist($conn_id, '/');

foreach ($ftp_rawlist as $v) {
$info = array();
$vinfo = preg_split("/[\s]+/", $v, 9);
if ($vinfo[0] !== "total") {
$info['chmod'] = $vinfo[0];
$info['num'] = $vinfo[1];
$info['owner'] = $vinfo[2];
$info['group'] = $vinfo[3];
$info['size'] = $vinfo[4];
$info['month'] = $vinfo[5];
$info['day'] = $vinfo[6];
$info['time'] = $vinfo[7];
$info['name'] = $vinfo[8];
$rawlist[$info['name']] = $info;
}
}
$dir = array();
$file = array();
foreach ($rawlist as $k => $v) {
if ($v['chmod']{0} == "d") {
$dir[$k] = $v;
}
}
foreach ($dir as $dirname => $dirinfo) {
if ($dirinfo['month']==date('M'))
{
if ($dirinfo['day']==date('d') || $dirinfo['day']==date('d')-1)
{
if (strlen($dirname)>3)
{
echo "[ $dirname ] " . $dirinfo['chmod'] . " | " . $dirinfo['owner'] . " | " . $dirinfo['group'] . " | " . $dirinfo['month'] . " " . $dirinfo['day'] . " " .

$dirinfo['time'] . "<br>";
unset($ftp_rawlist2);
unset($v);
$ftp_rawlist2 = ftp_rawlist($conn_id, '/'.$dirname.'/');


foreach ($ftp_rawlist2 as $v) {
$info = array();
$vinfo = preg_split("/[\s]+/", $v, 9);
if ($vinfo[0] !== "total") {
$info['chmod'] = $vinfo[0];
$info['num'] = $vinfo[1];
$info['owner'] = $vinfo[2];
$info['group'] = $vinfo[3];
$info['size'] = $vinfo[4];
$info['month'] = $vinfo[5];
$info['day'] = $vinfo[6];
$info['time'] = $vinfo[7];
$info['name'] = $vinfo[8];
$rawlist2[$info['name']] = $info;
}
}
//unset($dir);
//unset($file[$k]);
$dir = array();
$file = array();
foreach ($rawlist2 as $k => $v) {
if ($v['chmod']{0} == "-") {
$file[$k] = $v;
}
}
}
foreach ($file as $filename => $fileinfo) {
if ($fileinfo['month']==date('M'))
{
if ($fileinfo['day']==date('d') || $fileinfo['day']==date('d')-1)
{
$length = strlen($filename);
$characters = 3;
$start = $length - $characters;
$ending = substr($filename , $start ,$characters);
//echo $ending;
if ($ending=='txt')
{
if ($fileinfo['size']<'10000000')
{
echo "$filename " . $fileinfo['chmod'] . " | " . $fileinfo['owner'] . " | " . $fileinfo['group'] . " | " . $fileinfo['size'] . " Byte | " . $fileinfo['month'] .

" " . $fileinfo['day'] . " " . $fileinfo['time'] . "<br>";
//unset($filename);
}
}
}
}
}
}
}
}

}
rawlist_dirdump();



//ftp_close($conn_id);

echo "done";
echo "<br>";
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";
?>
it works, to provide a file list, except that the list it provides looks like this:
[ 10143 ] dr-x------ | mysasid | System | Dec 28 08:04
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
[ 10905 ] dr-x------ | mysasid | System | Dec 28 19:39
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
[ 11035 ] dr-x------ | mysasid | System | Dec 29 04:45
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
11035-11.txt -r-x------ | mysasid | System | 2392918 Byte | Dec 28 04:04
11035-18.txt -r-x------ | mysasid | System | 7308907 Byte | Dec 28 04:30
11035-188.txt -r-x------ | mysasid | System | 9285976 Byte | Dec 28 06:24
11035-29.txt -r-x------ | mysasid | System | 6468664 Byte | Dec 28 06:21
11035-31.txt -r-x------ | mysasid | System | 2989439 Byte | Dec 29 04:17
11035-34.txt -r-x------ | mysasid | System | 6460487 Byte | Dec 29 04:45
11035-342.txt -r-x------ | mysasid | System | 8224545 Byte | Dec 29 03:56
11035-4.txt -r-x------ | mysasid | System | 4069620 Byte | Dec 28 06:22
11035-61.txt -r-x------ | mysasid | System | 191137 Byte | Dec 28 03:59
11035-64.txt -r-x------ | mysasid | System | 184964 Byte | Dec 28 06:52
11035-73.txt -r-x------ | mysasid | System | 836110 Byte | Dec 28 06:41
11035-77.txt -r-x------ | mysasid | System | 1098 Byte | Dec 28 04:31
11035-85.txt -r-x------ | mysasid | System | 4390407 Byte | Dec 28 07:26
readme.txt -r-x------ | mysasid | System | 671 Byte | Dec 29 03:00
store_list.txt -r-x------ | mysasid | System | 3034 Byte | Dec 29 03:00
[ 11155 ] dr-x------ | mysasid | System | Dec 28 08:21
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
11035-11.txt -r-x------ | mysasid | System | 2392918 Byte | Dec 28 04:04
11035-18.txt -r-x------ | mysasid | System | 7308907 Byte | Dec 28 04:30
11035-188.txt -r-x------ | mysasid | System | 9285976 Byte | Dec 28 06:24
11035-29.txt -r-x------ | mysasid | System | 6468664 Byte | Dec 28 06:21
11035-31.txt -r-x------ | mysasid | System | 2989439 Byte | Dec 29 04:17
11035-34.txt -r-x------ | mysasid | System | 6460487 Byte | Dec 29 04:45
11035-342.txt -r-x------ | mysasid | System | 8224545 Byte | Dec 29 03:56
11035-4.txt -r-x------ | mysasid | System | 4069620 Byte | Dec 28 06:22
11035-61.txt -r-x------ | mysasid | System | 191137 Byte | Dec 28 03:59
11035-64.txt -r-x------ | mysasid | System | 184964 Byte | Dec 28 06:52
11035-73.txt -r-x------ | mysasid | System | 836110 Byte | Dec 28 06:41
11035-77.txt -r-x------ | mysasid | System | 1098 Byte | Dec 28 04:31
11035-85.txt -r-x------ | mysasid | System | 4390407 Byte | Dec 28 07:26
readme.txt -r-x------ | mysasid | System | 671 Byte | Dec 29 03:00
store_list.txt -r-x------ | mysasid | System | 3034 Byte | Dec 29 03:00
[ 11212 ] dr-x------ | mysasid | System | Dec 28 10:07
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
11035-11.txt -r-x------ | mysasid | System | 2392918 Byte | Dec 28 04:04
11035-18.txt -r-x------ | mysasid | System | 7308907 Byte | Dec 28 04:30
11035-188.txt -r-x------ | mysasid | System | 9285976 Byte | Dec 28 06:24
11035-29.txt -r-x------ | mysasid | System | 6468664 Byte | Dec 28 06:21
11035-31.txt -r-x------ | mysasid | System | 2989439 Byte | Dec 29 04:17
11035-34.txt -r-x------ | mysasid | System | 6460487 Byte | Dec 29 04:45
11035-342.txt -r-x------ | mysasid | System | 8224545 Byte | Dec 29 03:56
11035-4.txt -r-x------ | mysasid | System | 4069620 Byte | Dec 28 06:22
11035-61.txt -r-x------ | mysasid | System | 191137 Byte | Dec 28 03:59
11035-64.txt -r-x------ | mysasid | System | 184964 Byte | Dec 28 06:52
11035-73.txt -r-x------ | mysasid | System | 836110 Byte | Dec 28 06:41
11035-77.txt -r-x------ | mysasid | System | 1098 Byte | Dec 28 04:31
11035-85.txt -r-x------ | mysasid | System | 4390407 Byte | Dec 28 07:26
readme.txt -r-x------ | mysasid | System | 671 Byte | Dec 29 03:00
store_list.txt -r-x------ | mysasid | System | 3034 Byte | Dec 29 03:00
11212.txt -r-x------ | mysasid | System | 226672 Byte | Dec 28 10:07
where I want it to look like this:

[ 10143 ] dr-x------ | mysasid | System | Dec 28 08:04
10143.txt -r-x------ | mysasid | System | 251688 Byte | Dec 28 08:04
[ 10905 ] dr-x------ | mysasid | System | Dec 28 19:39
[ 11035 ] dr-x------ | mysasid | System | Dec 29 04:45
11035-11.txt -r-x------ | mysasid | System | 2392918 Byte | Dec 28 04:04
11035-18.txt -r-x------ | mysasid | System | 7308907 Byte | Dec 28 04:30
11035-188.txt -r-x------ | mysasid | System | 9285976 Byte | Dec 28 06:24
11035-29.txt -r-x------ | mysasid | System | 6468664 Byte | Dec 28 06:21
11035-31.txt -r-x------ | mysasid | System | 2989439 Byte | Dec 29 04:17
11035-34.txt -r-x------ | mysasid | System | 6460487 Byte | Dec 29 04:45
11035-342.txt -r-x------ | mysasid | System | 8224545 Byte | Dec 29 03:56
11035-4.txt -r-x------ | mysasid | System | 4069620 Byte | Dec 28 06:22
11035-61.txt -r-x------ | mysasid | System | 191137 Byte | Dec 28 03:59
11035-64.txt -r-x------ | mysasid | System | 184964 Byte | Dec 28 06:52
11035-73.txt -r-x------ | mysasid | System | 836110 Byte | Dec 28 06:41
11035-77.txt -r-x------ | mysasid | System | 1098 Byte | Dec 28 04:31
11035-85.txt -r-x------ | mysasid | System | 4390407 Byte | Dec 28 07:26
readme.txt -r-x------ | mysasid | System | 671 Byte | Dec 29 03:00
store_list.txt -r-x------ | mysasid | System | 3034 Byte | Dec 29 03:00
[ 11155 ] dr-x------ | mysasid | System | Dec 28 08:21
[ 11212 ] dr-x------ | mysasid | System | Dec 28 10:07
11212.txt -r-x------ | mysasid | System | 226672 Byte | Dec 28 10:07

It seems that I am unable to find the correct array to empty, no matter what I try. Can anyone help me with my error? it would be much appreciated. Just so you understand where I'm going with this, once I have the proper file list, I'll be downloading the files nightly to my server. Once I get this working, I'll probably change it to zip files, or gz files for efficiency as well.

If you could help me get this working I would appreciate it, or if you have know where I can get a free pre-made script to do this function, that would be handy as well, why re-invent the well...

Thanks in advance

Meriad
#correctly #destroy #make #variable #work
  • Profile picture of the author ussher
    Originally Posted by meriad View Post

    it works, to provide a file list, except that the list it provides looks like this:
    [ 10143 ] dr-x------ | mysasid | System | Dec 28 08:04
    where I want it to look like this:

    [ 10143 ] dr-x------ | mysasid | System | Dec 28 08:04
    I don't get it. The before and after look the same....

    are you talking about the whitespace? try trim() function.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5320562].message }}
    • Profile picture of the author meriad
      What I am referring to, is how the files repeat itself each loop it goes thru. It should look like this:

      dir a
      file a
      dir b
      file b
      dir c
      file c
      dir d
      file d

      instead of how it looks right now:

      dir a
      file a
      dir b
      file a
      file b
      dir c
      file a
      file b
      file c
      dir d
      file a
      file b
      file c
      file d

      My idea, is instead of displaying the 'echo' that displays the file info, replace that line with the ftp commands to download the file. How the script is now, 'file a' would be downloaded 4 times in the example above, instead of once.
      {{ DiscussionBoard.errors[5321468].message }}
  • Profile picture of the author meriad
    I assumed that much already, but I tried to unset some of the variables, but can't figure out why it's not working...
    {{ DiscussionBoard.errors[5322002].message }}
  • Profile picture of the author meriad
    Thanks Michael for the PM
    {{ DiscussionBoard.errors[5324677].message }}
  • Profile picture of the author ussher
    @DEaFeYe don't you just hate it when the [ code ] function in a coding forum doesn't work.......
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5326595].message }}

Trending Topics