Jump to content

transfer a file from one directory to another


dreamwest

Recommended Posts

I need to transfer a file from one directory to another, but this script loads endlessly.

 

$dir = "/htdocs/user/videos/";
$backup = "/htdocs/user/backup/";

$file = video.flv;

//**check if file exists**//
$filename = $dir . $file;

if (file_exists($filename)) {
    echo "<font color\"green\">The file exists</font>";

$current = file_get_contents($dir . $file);
file_put_contents($backup . $file);

}else{
echo "no";
}

<?php
$fromdir = '/path/to/directory';
$todir = '/path/to/new/directory';
$files = scandir($fromdir);
foreach ($files as $file) {
    if ($file[0] !== '.') { // escapes ., .. and files starting with a . (mostly hidden files)
        $filesource = implode(DIRECTORY_SEPARATOR, array($fromdir, $file));
        $filedestination = implode(DIRECTORY_SEPARATOR, array($todir, $file));
        copy($filesource, $filedestination);
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.