tables(i think) and uploadin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

tables(i think) and uploadin

Post 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!
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post 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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post by Alexia »

no i mean <table> like html table
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post 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.
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post 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.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

string concatenation.

Code: Select all

$str1 = "Hello ";
$str2 = "World";
$hello = $str1 . $str1;
echo $hello . "!"; //echos Hello World!
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post by Alexia »

oh, thanks, always wondered
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
Alexia
Forum Newbie
Posts: 18
Joined: Fri Dec 05, 2003 6:25 pm

Post 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!
Post Reply