dreamwest Posted July 10, 2009 Share Posted July 10, 2009 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"; } Link to comment https://forums.phpfreaks.com/topic/165460-transfer-a-file-from-one-directory-to-another/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 <?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); } } Link to comment https://forums.phpfreaks.com/topic/165460-transfer-a-file-from-one-directory-to-another/#findComment-872673 Share on other sites More sharing options...
dreamwest Posted July 10, 2009 Author Share Posted July 10, 2009 Thanks. But can this be limited to one file. Im pulling the filename from the database. Im trying to filter out unwanted files Link to comment https://forums.phpfreaks.com/topic/165460-transfer-a-file-from-one-directory-to-another/#findComment-872674 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 <?php $filesource = implode(DIRECTORY_SEPARATOR, array($fromdir, $file)); $filedestination = implode(DIRECTORY_SEPARATOR, array($todir, $file)); copy($filesource, $filedestination); ?> Link to comment https://forums.phpfreaks.com/topic/165460-transfer-a-file-from-one-directory-to-another/#findComment-872722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.