Page 1 of 1

tables(i think) and uploadin

Posted: Sun Feb 29, 2004 3:12 am
by Alexia
Hi every one, ok i was wondering:

Is there a way to upload a file to a diff host then on the host that the script is on? see i want users to be able to upload files on to there game servers, but for that to work, it'd have to upload to the web server, then the game server! (using ftp) is there any other way? (hope i explained good)

ok 2:

I've always wondered, how do you make a script show new tables? like for example, a forum, when you go into a catogory, php makes all the tables, how do you do that? i hope i explained good..thanks!

Posted: Sun Feb 29, 2004 5:43 am
by qads
1)

yes you can do with FTP, i have setup soemthing like this for a client, except i copy the file from the game server to website server, it is very easy to do:

take a look at [php_man]ftp[/php_man] functions, you will need ftp copy function.

this is what you need to do (IMO)
- allow user to upload the file to your website server
- copy the file with ftp function to game server.
- delete the file on website server to save space.

thats it...

2)
mysql doest have a function to tell you what table is new...there is a way though but its kinda hard to expline lol, i will post later when i can think of some words for it lol.

Posted: Sun Feb 29, 2004 11:51 am
by Alexia
1) ok, i just thought there might be another way, seeing as that takes x2 longer, oh well

2) ok i think i got a better explaination:

Ok, im making this download script, i want it to display uploaded files on the index of the page, so i would have to use tables, correct? but i cant figure out how to set tables like that in php

thanks

Posted: Sun Feb 29, 2004 2:22 pm
by qads
yep, the file has to be uploaded to your server first, no other way (imo).

2)
your having problems making the tables? if so, download phpmyadmin and set it up, that will make tables like bed time story..with a happy ending lol.

Posted: Sun Feb 29, 2004 5:41 pm
by Alexia
no i mean <table> like html table

Posted: Sun Feb 29, 2004 6:49 pm
by andre_c
You can do something like this:

Code: Select all

<table>
<php?
$dir = 'path/to/your/files/';

if (is_dir($dir)) {                                               //if directory exists
    if ($dh = opendir($dir)) {                              //save to handle
        while (($file = readdir($dh)) !== false) {    //read each file
            
  // if file is not parent or current directory (unix) or Thumbs.db (Windows)
            if ($file!="." && $file!=".." && $file!="Thumbs.db") {  
                echo "<tr>\n";                      // start a table row
                // make a table cell and link to the file
                echo '<td><a href="' . $dir . $file . '">' .$file . '</a></td>';
                echo "</tr>\n";                      // end the table row
            }				
        }
        closedir($dh);                               // close the directory
    }
}
?>
</table>
I hope that helps

Posted: Sun Feb 29, 2004 6:56 pm
by Alexia
andre_c wrote:You can do something like this:

Code: Select all

<table>
<php?
$dir = 'path/to/your/files/';

if (is_dir($dir)) {                                               //if directory exists
    if ($dh = opendir($dir)) {                              //save to handle
        while (($file = readdir($dh)) !== false) {    //read each file
            
  // if file is not parent or current directory (unix) or Thumbs.db (Windows)
            if ($file!="." && $file!=".." && $file!="Thumbs.db") {  
                echo "<tr>\n";                      // start a table row
                // make a table cell and link to the file
                echo '<td><a href="' . $dir . $file . '">' .$file . '</a></td>';
                echo "</tr>\n";                      // end the table row
            }				
        }
        closedir($dh);                               // close the directory
    }
}
?>
</table>
I hope that helps
Thats exactly what i wanted, thank you.

Posted: Sun Feb 29, 2004 7:41 pm
by Alexia
ok, sorry for this offtopic questions:

what does . do? like ' . $dir . $file . '">' .$file . ', my book didnt explain that very well, and

whats @ mean? like in @copy() ?

Thanks.

Posted: Sun Feb 29, 2004 7:57 pm
by Illusionist
string concatenation.

Code: Select all

$str1 = "Hello ";
$str2 = "World";
$hello = $str1 . $str1;
echo $hello . "!"; //echos Hello World!

Posted: Sun Feb 29, 2004 9:53 pm
by Alexia
oh, thanks, always wondered

Posted: Mon Mar 01, 2004 8:21 am
by qads
@ in front of function means it wont print a error message if it cant do what it was asked to, very useful when you dont want to show where you were trying to copy a file etc, dont use it when you are working on the script. put it in when the script is working :D.

Posted: Mon Mar 01, 2004 4:20 pm
by Alexia
qads wrote:@ in front of function means it wont print a error message if it cant do what it was asked to, very useful when you dont want to show where you were trying to copy a file etc, dont use it when you are working on the script. put it in when the script is working :D.
ohh!!!! thank you ! thats great!