Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Move files from one folder to other using PHP

0 views
Skip to first unread message

ssp2000

unread,
Jan 8, 2004, 7:58:20 AM1/8/04
to
Hi all

I am using PHP4 on win2k plateform.
I want to move existing files from one folder to another. How can i
achive that by using PHP? I am not doing (and donot want to) uploading
of files via HTML Form , nor i want to use ftp. It is simply , moving
of existing files from one folder to another.All file system
permission are in our favours , no restrictions.
ssp2000

Erwin Moller

unread,
Jan 8, 2004, 8:37:59 AM1/8/04
to
ssp2000 wrote:

As written in the documentation.
<?php
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
?>

Check www.php.net and go to documentation on 'file', you will also find ways
to get a directorylisting. You'll need a directorylisting to get all
filenames.

finding files in a directory:
1) glob:
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}

2) opendir
<?php
$dir = "/tmp/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) .
"\n";
}
closedir($dh);
}
}
?>


Regards,
Erwin

ssp2000

unread,
Jan 9, 2004, 5:55:50 AM1/9/04
to
Thanks for you input. glob requires PHP 4 >= 4.3.0

Erwin Moller

unread,
Jan 9, 2004, 6:06:08 AM1/9/04
to
ssp2000 wrote:

> Thanks for you input. glob requires PHP 4 >= 4.3.0

In that case use: opendir
But I guess you figured that yourself. :P

Good luck.
Regards,
Erwin Moller


0 new messages