Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Copy Files And Folders From One Directory Into Another


I have files in myurl.com/myfolder

and I would like to copy all of them into

myurl.com/newfolder

I'd like to copy all of the subdirectories and files that are in
/myfolder

and I would like to be able to use a form of some sort to name the
file I want to copy, and create the folder I'd like to copy it to,
such as newfolder.

How can I use a form to create a new folder on the server?

How can I use a form to name the old folder I want to copy everything
from, then create the name of the new folder I want to copy everything
into, and then copy?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Copy Files And Folders
Assuming you had a template folder and files on the webspace and you
wanted to make a exact copy/rename of it with a username and password
being the one and only difference - how would one do it ? .

(the difference being a password protected folder)

Creating Dir, Copy Files And Pass Variables To 2 Files
I need to create a folder on the server weekly named by the user. To this folder copy the contents of an /Original folder. Inside the new folder edit one of the files to insert a data with a XML path generated in another application, copied (via memory) and pasted within the very first form and passed to the file in question.

<param name="FlashVars" value="xmlfile= $lanofile" />

the $lanofile is the value that I need to pass from the form to be read by this file.
I have created an form (n.php) that POST the name of the folder to a second file (creatdir.php) everything is cool until I have to edit the third file.

How can I pass the value of one of the formfileds to a second file and them read this value as a variable to be consumed as mentioned above? Or actually right whatever is on the third field to this position (not using variables).

Files And Folders
I need to display images on the site. Every image is being stored in its own folder. Folders are updated daily. I need to display a list folders (like FTP), and when a user clicks on a folder name, it will show them other folders inside the parent folder, or if there are no more folders inside picture files will be opened. I know how to get a list of files and open them when I am in a current folder. PHP Code:

Copy From One Directory To Another Using PHP
I am a novice at php and need to know how to move files from one
driectory to another on our website. I know this is an easy script but
I have no idea on how to do this.

Move Files And Folders
is there any php command for it? like copy() or rename();

Using Files/folders To Create A DB
I'm always looking for ways to decrease the amount of time I spend adding records to my database. I was thinking about this today, and wondered if it was possible....

I want a PHP script to open a folder or folders, read the files, and make a record in the database for each file. For example: Folder 1 contains the files--4000out.jpg, 3000bcr.jpg, 4000btcf.jpg, etc...

When excuted, the script would create (in this case) three records. I only want the script to do the base work, I will add what can't be done to the records later.

Also, in the case with mp3's. I'd like the script (or a seperate one) to insert each record using the ID3v1 tag info. I'm familiar with open files and folders...but haven't come across any tutorials or scripts that do this. So...is this possible?

Directory Copy Question
I noticed that I can't remove the folder that I created because it says "Directory not empty" so I did a little investigation on my PC machine. I used telnet to get to my folders and did a ls -a and noticed that all of the files had an asterik on the end of them and it had a file called .gif* in there as well. So, when I deleted all the files in the folder it deleted all of them BUT the .gif* and thus I cannot delete the folder through ftp on my mac.

whew!! Finally my question:
Is this normal to have an asterik at the end of a file name when using a repetitive copy funtion like this? AND is there something wrong with my code that is forcing a file called .gif* to be created?

Here is what I have:

I am setting the variables prior to this function call.
-----------------
Calling the function like this:
getImages($sourceimagefolder,$imagepath);
------------------

Here is the function: (thanks to dusty2k by the way)
function getImages($sourceimagefolder,$imagepath) {

if ($handle = opendir($sourceimagefolder)) {

echo "Source Directory: $sourceimagefolder<br><br>";

echo "Destination Directory: $imagepath<br><br>";

echo "Files:<br><br>";

while($file = readdir($handle)) {

if($file != "." && $file != "..") {

if(copy($sourceimagefolder . $file, $imagepath . $file)) {

echo "$file copied successfully.<br>";
}
}
}

closedir($handle);

}
}

Creating And Deleting Folders And Files
Hi to Everyone.

After creating trought http a organize number of files and folders. I'm not able to delete them, not even trought an FTP Software like Cute FTP. It replies "Could not delete xxxxx.html".

Recursive Delete All Files/folders
I want to delete all file and folder recursivly under php code, can
anyone give me commend for this.

Restrict Access To Folders/files
On a website, I will have several PDFs that I need to make available if user gives correct password or is in a given IP range. My first thought was to use .htaccess, but the host doesn't support that. they do support .htconfig and I didnt find any way of using that to resolve my needs.

If there any walk around in this situation using PHP and MySQL?

Generate New Files/Folders For A New User
I am starting to get into PHP and I was wondering if there was a way to have a PHP script that first always a guest to register (which I know there are millions out there). Second I would like after registration is complete, a PHP script will automatically copy and paste files into the users directory. For Example:

Bob just signed up on my website with the username Bob123

After he completes the registration, a Script will generate a folder called Bob123 (www.domain.com/Bob123) With files like index.htm and logo.gif in there.

Is this possible?

Copy A Directory With Security Permissions
I am trying to make a page that will accept input from a user and create a directory structure from the input then fill that directory with the contents of a template directory and put the correct permissions back to the folders. This is on windows 2k server using active directory. a small sample of what I am trying to do: Code:

Security Read Write Files And Folders
when i upload files to my webspace i set permission to my files and folders. Im wondering how im unsafe if i grand a folder or file with write permissions to all/everybody. In fact I have the intelligence to understand that ones can places files to my webspace and then execute them. But I dont have the knowledge how to implement it.

How can i write to that folder and files?

Copy Files To A Different Dir?
I have a file which is located in "/usr/home/coreyr/html_files" and I want to copy it to "/usr/home/public/html" I've tried the following and I receive errors.

<?php copy('sf.html', '/usr/home/public/html'); ?>
any ideas?

Copy Files From Remote URL
how can I copy a file from a url into the directory where my php file is located?

On the server I use it is not possible to use the copy() function for this task.

Recursive Copy Of Folder/files
I want to copy entire content(have both files and folders)from One folder to destination folder..

Files From Directory
I'm looking for a function that returns all files from a given
directory...

Directory For Php Files
What are the advantages of putting php scripts in folders and sub folders in terms of security advantages.. i know it helps for knowing where everything is and its neater but is there any difference in terms of security?

And also if it does help security should the directories be difficult to guess so that attacks can't happen or something? Because at the moment my php files are all in htdocs folder they are not separated into folders like:

includes folder
session folder
etc etc

Some one mentioned about permissions is the more important thing but I don't know what it is =/.

Zipping All Files In Directory
I need to come up with a script hat will zip all the files in a directory at download. I am working with a virtual host and couldn't tell you if they have any zipping functions compiled with php.

Can i still do this? Also how would i find out if the zipping functions are compiled in php?

I have never done this before and am drawing a blank on what i should be looking for or at.

Thanks guys

Number Of Files In A Directory
I hope someone can help me out. I'm just starting witch php actually and for something I figured out, I would need to know how many files there are in an directory at that time.

How Do I Find Certain Files In A Directory?
I need to find all the files in a directory that have a particular extension (like .txt), and then load the contents of those files into MySQL. I understand how to find a specific file, but I'm not sure how to read an entire directory, then grab only those files that have the extension. Also, should I be concerned about the server timing out, or anything of that nature, since there might be as many as a few hundred files that I'll be loading into the database.

Files Sorting In Directory
Can anybody tell me how files are sorted in remote directories on an Apache server?

I am working with files and directories in php, having pictures in a directory and let php find and display them automatically. However, the sorting of the pictures is all mixed up, they only seem to be sorted by filename, but are in some cases not. I have experimented with uploading them once again, all in a bunch as well as picture by picture. it gives me various results, I can not recognize any pattern in the sorting.

Can I Put Some Php Files In /var/www/ In A Directory Other Than Html?
I setup a local sever, the sever pages are in the /var/www/html/ and when i start the server, it opens the /var/www/html/index.html that is ok, now my question, there is some php files can i put them in a deferent directory then html in the /var/www/ for example /var/www/any_name, and then how i can open them with my server?

How To Check Files In A Directory
I have a txt file in a directory that I want to display on my website with PHP, that's no problem. Say that every hour later, a new txt file gets uploaded to the directory.

1) How can PHP display ALL the text files on a webpage in order from latest to first?

2) This can be done manually by just changing the PHP code every hour, but is there a way so that I don't have to change the code everytime a new text file gets added, so that its done automatically?
(ie. how can it check for new files to show?)

Deleting All The Files In A Directory
Using PHP 4, what are the shortest amount of lines I can write to
delete all the files in a given directory?

Count Files In A Directory
Using PHP 4, is there a fucntion that counts the files in a
given directory? You can assume there are no sub-directories within
this directory and hence, no files within the sub-directories.

Count Files In Directory
How can I count only .jpg files from a specific directory, put the .jpg filenames into an array to and replace these filenames with a random number?

Require All Files Within Directory
I'm trying to figure out how to create a script that will read the directory "req" and automatically include all files within it. Right now, I have manually added each file into a list. I attempted to use a parse directory code I found on this forum, but it didn't work. Is this some special way I could do this? require.all.php PHP Code:

PHP Files Only Run In Root Directory?
I've installed a php forum script under a directory named 'forum', the script ran with no problems untill about a week ago, but now I get the following error: 'You don't have permission to access /forum/index.php on this server.'

Its has nothing to do with CMOD, I've tried that. Worst still it's not just the forum it's any PHP file thats under a directory. The thing is, I can run a PHP file from the root directory, but for some reason can't run the same file under another directory.

eg www.mywebsite/testfile.php --- will work fine www.mywebsite/newdirectory/testfile.php --- causes permission error

Could it be a .htaccess problem? Heres my error log report: Options ExecCGI is off in this directory: /home/mywebsite/public_html/forum/index.php P.S The forum script dosn't use CGI?

Counting Files In A Directory?
How could I account how many files there are in a directory and echo the amount?

Hiding Files Within A Directory
I'm looking for a PHP code that will hide (not unset) any filename within a directory that doesn't end in a particular extension (i.e. ".txt") from showing up in an array using foreach.

In this case, I am only showing txt files in an array displayed in an HTML selection form element. I'm a total newbie at PHP (taking my first PHP course ever) and am entirely stuck on this. 

Delete Certain Files From A Directory...
Is there any way to make a function that deletes all files of a certain EXTENSION? let's say ".txt" files... how could you use the unlink command to delete all files that have the extension ".txt"?? I know how to recursively unlink all files in a directory, but I can't seem to figure out how to delete all files with a certain extension...

Linking To All Files In A Directory
I'm trying to do is set up a directory that will contain a bunch of different web pages and have any web page in that one directory linked on the nav.php  automatically. Lets say I have 3 files in my stuff/ directory, named file1.php, file2.php and file3.php.

In the nav.php I want a script that will generate this html for every page

<a href="/stuff/$file">$name</a>
where $file is the file name in the directory, and $name is a variable defined within the file its self.

Files And Directory Extensions
I'm currently running a website that generates dynamic images for users, for use in their signatures on forums. For example, I have created an image file (using PHP) and the address is http://www.website.com/tags/tag.php?u=Flava (an example).

However, it seems that some forums block the ?u=Flava and so doesn't display it correctly - so instead, I would prefer to link to addresses such as http://www.website.com/tags/Flava.php (so that the users username, is in fact the filename). I know this is possible as I have seen it done elsewhere, however I am not too sure how to achieve it.

Listing Files In A Directory
im trying to list files in a directory, the directory contains many different types of files like images, pdf's, sub directories, txt files and other php files. what i wanna do is list the files with links to each of them, but with images i want a little thumbnail to show up next to it. Code:

List Php Files In Directory.
I am creating a plugins folder that  I will use to store php files. I also store other folders within that "plugins" folder. The problem I have is getting the script to read only the  the .php files and skip subfolders.

Plugins[main folder]
    ->plugin1.php
    ->plugin2.php
    ->screenshot[folder]
    ->downloads[folder]

How to keep the script from checking the folders (screenshots, downloads..) This part of my script filters the main folder and parent but not subfolders

if ($file!= "." && $file!= "..") {

How do i get that code to not check subfolders.

Writing Files To A Directory
How do i write files to a directory? i can only figure out how to make the site open files in the same directory as as the script file, is there osme way to tell it to read or write a directory? say in /files/?

Print All Files In A Directory.
I am building a control panel for a hosting website, and I was wondering if there is a way to display all the files in a directory .

Directory Listing With Links To Files
I am trying desperately to write code that will search a directory, create links to all files and subdirectories in it, and allow you to download, PDF, DOC and XLS files from it. I'm not having any luck. Can someone please point me to some code that is similar so I can modify it and learn how it works?

Problem Listing All Files In A Directory
I am having a wierd problem with PHP. I am using it to get all the file names in a particular directory. Everything works fine until I create any file with no extention in the directory being read. Then page doesnt load anything (I get the error message "Document contained no data. Try again later or contact the server administrator" ) The page starts working fine as soon as I remove the extention less file or give it an extention (any extention)

I am using opendir() & readdir() to traverse the directory. There is text in the php file other than the file listing.

Including Files From Entire Directory
I have this little news script that stores each entry into a seperate file into monthandyear/day, month date, year hour-minutes-seconds AM/PM

so if it was Sunday, March 9, 2003 11:39 PM then the script would store the new entry in the folder named "March2003" and in a file called "Sunday, March 9, 2003 11-39-00 PM"

now, the problem i have is i want to have an archive of all my news entries by month, so how do i get the contents of all the march entries displayed onto one page in order of date and time?

Delete A Directory And All Its Files And Sub-directories?
Does anyone know of, or have code that will delete a php directory and
all its sub directories and files. "unlink" and "rmdir" don't do this.
I'd prefer not to use "exec" with a system call but if that's the only
way, so be it.

Directory Permissions When Managing Files In PHP
I am some scripts that allow users to upload images. However in order to make it work i have to change the permissions of the directory to 777, is this not secure? Is there a better way?

Select Random Files Out Of A Directory
for example, there are 10K files in the directory,

given that i don't know if files name, is it possible to fetch a file
randomly?

Check A Directory For Files To Import
I want our company employees to be able to update our website with special formated emails. My IT guy has made a perl script to parse the email to a text file formatted the way I want.

I want him to dump the txt file into a directory, that is being watched. When a new file is put there, I want something to pass the name onto my PHP script, so it can run, and import the file into mySQL. My PHP script works if I tell it what the name of the file is, but I have to execute the script myself. I am not sure if I can use PHP to monitor the folder for new files, or if I need to use a crontab, or what?

Writing Files To A Choosen Directory
I have the following code which changes directory, creates a file and then
writes rows to it. It works fine except the file is created in the folder
the php script is in instead of the download directory specified in the
scrip. Can anyone see where I have gone wrong
Also I want to show the question Index and Question on screen as a list.
Ive put

echo $nt['QuestionIndex'], $nt['Question'];

******************************
$query= "SELECT * FROM Questions WHERE NCIndex='".$_SESSION['NCI']."' AND
QuestionIndex IN (".join(",", $_SESSION['questions']).") ORDER BY
QuestionIndex";

$rt=mysql_query($query)
or die(mysql_error());
echo mysql_error();

if (ftp_chdir($conn_id, "../htdocs/Downloads")) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "
";

}else {
echo "Couldn't change directory
";
}
$fp = fopen('ptq'.$_SESSION['username'].time().'.txt', 'w')
or die('Could not open the text file for writing');
while ($nt = mysql_fetch_array($rt, MYSQL_NUM)){

$line = "INSERT INTO tQuestions VALUES ('', '" .
implode("', '", $nt) .
"');
";
fwrite($fp, $line);
echo $nt['QuestionIndex'], $nt['Question']; <<<<<<<<<<<<<<<
}
fclose($fp);

***************************

Dynamic Links To Files In Same Directory
is it possible to make a php file for instance in my localhost htdocs folder and code is so that it automatically and dynamically displays links to all php/html files in that same directory when i hit it up in thew browser?

My Localhost Shows All Files In The Directory?
How do i make index.php as my default file to open when i typed http://localhost of my desktop.

Includin Files In The Parent Directory
Here is my file index.php:

<?php
include "../parent.php";
?>

When I try to run this code on a Linux server, it gives me the
following error message:

Warning: main(): open_basedir restriction in effect. File(../
parent.php) is not within the allowed path(s): (.) in
192.168.1.16webfilesfiles2007-61475215innerindex.php on line 3

Warning: main(../parent.php): failed to open stream: Operation not
permitted in 192.168.1.16webfilesfiles2007-61475215inner
index.php on line 3

Warning: main(): Failed opening '../parent.php' for inclusion
(include_path='.;c:phpincludes') in 192.168.1.16webfilesfiles
2007-61475215innerindex.php on line 3


Copyright © 2005-08 www.BigResource.com, All rights reserved