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




Copy Entire Contents Of A Folder To Another


Situation:

I am creating a folder based on input from a form and then creating an images folder underneath that -- that works great and I can read and write to the newly created folders AS LONG AS IT IS ONE FILE AT A TIME!!!

What I would like to do:

I would like to copy the contents of an entire folder over to one of the newly created folders ALL AT ONCE -- or in a loop -- which is what I am trying to do but keep getting denied.

My code as it is now:
if ($handle = opendir("$sourcedir")) {
echo "Directory handle: $handle<br><br>";
echo "Files:<br><br>";
while (false !== ($files = readdir($handle))) {
if ($files != "." && $files != "..") {
if (!copy($files, $imagepath)) {
echo "failed to copy $files into $imagepath<br><br>";
}
}
}
closedir($handle);
}

all of the variables are working fine... it goes through the loop just fine -- I know this because it prints out the error for every file in the folder... it just won't copy the files over to the new folder while in this loop.

Here is the beginning of the error messages:
Directory handle: Resource id #2
Files:
failed to copy step_c1.gif into /htdocs/www/schemes/adfasa/images
failed to copy step_b1.gif into /htdocs/www/schemes/adfasa/images
failed to copy step_a1.gif into /htdocs/www/schemes/adfasa/images

by the way: adfasa is the folder name brought in by the form and images is the folder I create underneath it.

Is this something that is possible to do in a loop? If so, what is wrong with this one. If not, how is something like this done?

Of course since I know the files that are in the folder I want to copy from I could just go ahead and copy them ONE by ONE but that doesn't seem to be very efficient.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Copy An Entire Array?
can I do this? You see, I want to pass my values in to another page, but you can imagine how it would be insane to try and copy each value in the array individually

<A HREF="thepage.php?array[0]=$array[0]&array[1]=$array[1]... etc

is there a way to compress an array into a single variable, and then decompress it

like:
Code: $compressedArray = compress(0, 10, $array);
where 0 is the start index, and 10 is the end index

then when I want to use it on the other page
Code: for ($x=0; $x<=10; $x++){
$newArray[$x] = decompressMe($x, $compressedArray);
}
I'm sure that there must be some simple little thing like that.... I looked at the php manual, but couldn't really see anything like I'm talking about (or maybe I dont understand it )

Drag Files From One Folder To Another Folder (copy) .. Possible?
Is it possible to write codings PHP or Javascript.. GUI representation
of File handling (ie. Drag files from one folder to another folder (copy)
like our windows).. pls give me some reference codings like this..

Any Way To Upload Entire Folder?
I'm currently working on a little program that will allow different departments within where I work to upload videos (like training videos or safety videos) and then keep track of who watches them. My guess is that I'll do most of the uploading myself, but I wanted to make it such that I can give anyone access to the upload script so they could do it themselves.

Anyway, we (at the office) all agreed that Flash is the best format for security and ease of distribution. We went out and got a program that will allow conversion of video files to flash and also allow them to have a nice table of contents and controls. The biggest problem is that for the TOC and controls to work on the flash videos, the program creates a friggin mess of files that all relate to each other... and this screws up my 'easy' upload idea. There's no way for this program to create a nice single .swf or .fla that has all the controls and TOC built in, at least not that I've found. :(

Is there any way, other than zipping up a directory and writing an unzipper for the server side, to allow a user to specify a directory where the video resides and just up the whole thing intact?

If not, I suppose I'll have to settle for the single .flv file that is created and dump the controls and TOC... though that's part of the reason we bought this converter program. I'm trying to write it in such a way that it will also play mpegs and avi files down the road if that's what the department has, but to start out we're asking that they send us the movie file so we can convert it to flash.

Copy Folder?
I want to copy a folder, subfolder, files, and subfiles.  I don't care about attributes. I thought about making the folder a zip, and then using extract but that was confusing and took too long on the server.

so what do I do?  Is there a script that will parse the dir and COPY all the files?

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

Getting And Using Contents In A Folder
I want to make a photogallery/slideshow with PHP...

The 'gallery/slideshow' would show up inside a new window.
basically, I just want links with possibility to go:

- forward
- back
- to the very beginning
- to the very end
- away (close the window)

Can I use PHP to determine the contents of the folder with the pictures and then use variables to determine which photo to show, and what URL's should be generates for the arrows? So each folder with a series of photographs would have one PHP file and the pictures themselves in them (it's not a problem to rename them).

Should be simple enough, but I'm just starting out with PHP, and I'd like to have something working as soon as possible... the website I'm working on is about to launch soon (my first 'commercial' web project :) ), and this is about the only thing left that I still have to sort out how to do...

Getting Contents Of Folder
I've made half of the code for a little "hosting" site for a few of the members of my site. Their files are uploaded to /login/<username>/

I'm now stuck as to how to show the contents of the folder in a page. I think the use of fopen() is needed, however the php website is a little confusing.

Delete Folder And Its Contents
is there any way of deleteing a folder and all of its contents using PHP?

Deleting Folder And Contents With PHP
Im using this code to delete a folder using my script but it says Directory not empty. What code could i use that will delete the folder, subfolders, and all its contents.

$currentdir = getcwd();
$directory="$currentdir/users/$_COOKIE[username]/albums/$_GET[albumname]";
rmdir($directory);

Folder Contents Function?
I'm looking for a function that puts the contents of a folder (the file names) into an array. Is there such a beast? For instance, if there is a folder off of my root called /tips/, and I want to list the files that are in it, such as tip1.txt, tip2.txt, etc.

Syncronizer - Synchornize Folder Contents
is there anyway to sync to folders Contents between two Computers in PHP...

List Contents Of A Folder, Make List Of Links
Does anyone know how I can write a script that:

- reads in all the files in a particular directory
- displays the file names in a html list and makes a link of them:
<ul>
<li><a href="filelocation1">filename 1</li>
<li><a href="filelocation2">filename 1</li>
<li><a href="filelocation3">filename 1</li>
</ul>

etc.?

So basically it creates a list of links with the contents in that directory,
so you can download them from there.

Remove From $name (folder)/(folder)/[x]/ <-- If Exists To Just Get [x].
I'll be quite honest. I don't have the faintest idea
how to do this, while I can do other php without a problem. Once I
know how to go about it I'll be okay.
It's two things I think?
1. see if there's a trailing slash and delete it.
2. Remove the preceding path to /x, the folders and slashes, and
delete them.
and then I have x.

X by the way is the final folder in a website and this grabs it for
me.

<?
$name = $REQUEST_URI;
?>

Getting The Entire URL
You know how someone submits a form, and it goes to process_form.php, and after processing, redirects it back to that page?

How can I get the URL of my page, and after the person submits the form, take them back? For example:

viewtopic.php?topic=32&post=4&id=33

Can I store that portion of my URL (along with all the variables)?

(I have heard of $_SESSION['url'])

What Can Return The ENTIRE Url?
I'm looking for PHP equivalent to Javascript's location.href property. This returns the ENTIRE url (including any variables that might be submitted to a script). I've looked at phpinfo(), but I didn't see exactly what I am after. If the answer is the HTTP_POST_VARS variable, could someone please give me a simple example of how exactly this variable is to be used in code?

Capturing The Entire URL
Been playing around with capturing the entire URL. I dont have any problems
if it a file,
i.e. http://www.mydomain.com/somefile.php, I am running into problems with
this,
http://www.mydomain.com/test

This is what I use for "redirection" now (btw, it is IIS (Win2k) and PHP
4.3.2)
The test.mydomain.com is setup as a host header under IIS

$redirect = getenv("HTTP_HOST");

if ($redirect=="test.mydomain.com"){
header("Location:http://www.mydomain.com/modules.php?name=test");
}

The above code works fine. Redirects no problem.

However, I am trying to get this to do the same thing:
www.mydomain.com/test or www.mydomain.com/test/
and both would take you here:
http://www.mydomain.com/modules.php?name=test

I have tried every combination of the SERVER vars, but no luck.
I either generate a 404 or the test isn't part of the URL.

Preventing Entire Db Download
I've collected some data and created a db. I am putting together a
website allowing users to search the db with a search-query
functionality. I am pretty much building a google-like engine,
although the data is stored in a MySQL.

If I use a GET form in the search page (which is what most engines
do), then the query results are displayed in pages where the URL
contains the query_string (example,
www.blahblah.com/search.php?queryitem1=my1&queryitem2=my2+my3).
So far so good, but in my case the data is of a local nature (say, a
yellow page type of thing with some extras) and someone can basically
pick the entire database by running a script like:

wget www.blahblah.com/search.php?zip=00001
wget www.blahblah.com/search.php?zip=00002
..........
wget www.blahblah.com/search.php?zip=99999

This is something I would like to prevent. Could someone please offer
their opinion on:

1. how to best go about it with a GET form?

2. Is it indeed doable with a POST form in the search page (as opposed
to a GET form)?

3. I've read that the main advantage of a GET vs POST form is that
someone can bookmark a search results page (eg.
www.blahblah.com/search.php?zip=12356) if it the form is GET. Any
other advantages/disadvantages that i am missing?

Passing An Entire Array In PHP
I saw a previous post about sending arrays but did not quite
understand the answers.

The problem is that I would like to pass an entire array as a hidden
input field from one php script to another. I've simplified the code
where form1.php calls form2.php when "Go" is hit:

form1.php
=========

<html>
<head>
<title>Form 1</title>
</head>
<body>
<h1>Form 1</h1>
<form action="form2.php" method=post>
<?
$record[0]="One";
$record[1]="Two";
printf("<input type=hidden name="record[]" value="%s">",$record);
?>
<input type=submit value="Go">
</form>
</body>
</html>

form2.php
=========
<html>
<head>
<title>Form 2</title>
</head>
<body>
<h1>Form 2</h1>
<?
$record=$_POST['record'];
printf("$record[0]=%s",$record[0]);
printf("$record[1]=%s",$record[1]);
?>
</body>
</html>

The result is:
Form 2
Array=Array=

How do I fix this?

Copying Entire Directories
I need to copy all of the files from one directory to another. This has to happen on the fly. The files that are being copied are actually templates for another site that will be created. I have seen the example on php.net under the fopen section but it doesnt work.

One File Throughout Entire Site?
I would like to have a file header.php used throughout my entire website. When I do this however it does not work 100% For example the file maybe in /home/header.php with 10 hrefs for the site. Then if a inc() in /home/dir1/dir2/ uses the file it will of course link wrong. For example Code: <a href="dir1/">

If this is in the header file in the /home dir then when the file in /dir2 uses it of course teh link will look like this to the broswer Code:
http://www.domain.com/dir1/dir2/dir1/ of course this is not what I want. Everytime I make a change I'm having to make it to over a 100 files so I would like this one file to be used throughout the entire site.

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?

Http Authenticate Entire Site
we are validating users in several different sections (each section is in it's own directory..ex. the download section is in /downloads) using http authentication. when a user authenticates in one section they can roam freely in that directory without having to authenticate again.

for some reason however, when i change to a different directory and then run a phpinfo(), both $PHP_AUTH_USER and $PHP_AUTH_PW are gone, meaning the user will have to authenticate again.

the user can go back to the first directory again and they are still authenticated within that directory. i would like the users to only have to authenticate once for the entire site, but scince there are areas of the site that do not require validation i don't want to make them authenticate until they have to.

Viewing Entire HTTP Header ?
is there a way in code to view the entire HTTP Header? Many of the
variables in $_SERVER have much of the header, as do some of the apache
functions, but none seem to have a way to show the body that was sent with
the request.

any suggestions for how i would go about doing this? It's mostly for
documentation and instructional purposes, but i'd like to see the results
without having to construct them by hand and telnet'ing into port 80 all
the time ....

Pass The Entire Array Through A Form.
Im working with an array in my php script and need to pass the entire array through a form. Here is the script. Take a look and tell me if you can see my mistake.

I create a dynamic entry screen that has multiple values that I would like to update and want to place them all into an array to update them. At the mo no values are being posted at all. Code:

Can You Send An Entire Webpage Via Email Using PHP?
If you go to File >> Send > Page via email

it will send a snap shot of the current page you are looking at via email.

can this be done via PHP (or another means) so that I can create a script that will email a webpage automatically to a chosen person?

Sending Entire Web Page To Email
Is it possible to send an entire web page to an email using mailto:person@blah.com function, with what has been typed in the text boxes. And if so what would the code look like.

Optimizing Dynamic Php Code (entire Site)
my web site seems to load rather slow because it accesses the db several times and there is a lot of code (because of features).

i was wondering how i could optimize/cache this so that the query is only executed once (until i modify the actual code).

any ideas?

Export Entire Site And Save As HTML
I feel as though I will be covering ground that others have posted, but I have searched and not found much at all.

Basically, my site is in PHP/mysql, but before I go online I want to save 95% of the site's output as HTML (basically everything but the search pages). This will be around 4,000 pages. Is there a way I can get PHP to save the output that a scirpt generates as a separate HTML file?

What I would like to do is build this feature into my admin menu. Thus, when I make a change to the database, I can pull up the individual record, and click on a button that says "rebuild html pages".

Using Just One Entry Point For An Entire Dynamic Site
I'm thinking of an architecture for a medium-complexity dynamic site
as follows:

- I use one php file, say a.php as the entry point for the entire
site. PATH_INFO allows me to pass information to my script by using
URLs like http://mysite.com/a.php/user1000 or
http://mysite.com/a.php/images/10.gif and perform the appropriate
action by calling the appropriate function (which may reside in an
included php file)

- I use apache's url rewriting to redirect urls like
http://mysite.com/page25 to a.php b adding the script name -
http://mysite.com/a.php/page25

- Using Smarty to control the actual HTML output.

This seems to me like a sound and obvious way to do things (and also
rarely done) so my questions are:

- Has anyone on this group tried to do or done something like this
before, using one entry point for the entire site for maximum control?

- If so, what do you think are the pros and cons or this approach?

Entire Query String As Script Variable
How would I pull the query string of an URL into my PHP script for use as a variable inside the script?

For example - URL is http://www.mydomain.com/hub.php?ref...bob&lname=smith

In my hub.php script, I want to set a variable

$foo = "ref=affiliate1&fname=bob&lname=smith";
(or whatever the actual query string happens to be)

PHP Http Authentication - Cannot Secure Entire Directories?
I've been trying out HTTP authentication with PHP (yes I've read the Zend tutorial, searched the forum, and read the manual). Things seem to work great.

However I have noticed that is does not work like a .htaccess file would. Only the PHP script which sends the headers will check for anything. No very useful for blocking out a whole directory tree. I wanted to move away from just using a .htaccess so that I could authenticate the passwords over a MySQL database.

The current setup has an index.php in the directory that is to be protected. It checks for password, then initializes a session and forwards the user to the protected section. Each script in the protected section checks if valid session exists, and if not, forwards back to the main index.php to HTTP authenticate again.

This seems to work fine except I'm afraid of one day forgetting to check for the session or people accessing non PHP files that are in the protected directory.

My question is, is there a way to combine PHP based http authentication with a .htaccess file? Or somehow have an entire directory be authenticated through one script. And the other concern is that if I do have the entire directory protected and go through that one PHP script somehow, wouldn't it have to check the l/p with MySQL every time they accessed any file?

Regular Expression Detecting Entire Page
I am making a flat file, static HTML search engine for a site. I
downloaded a script from the net and have been working with it for my
needs.

Everything was working OK with a few test Lorem Ipsum pages. But the
moment I try to search real data, fit hits the shan.

The script uses a regular expression to search through the files. And
for most of these files, the regular expression doesnt seem to pick up
the matches as it should, and for lack of a match, it outputs the
entire html page as a hit. The search word is on the page somewhere,
but it still outputs the entire page.

Allow me
--------8<----------------------------
if(preg_match_all("/((sS*){0,3})($keyword)
((s?S*){0,3})/i", $portion, $match, PREG_SET_ORDER));
{
if(!$limit_extracts)
$number=count($match);
else $number=$limit_extracts;

for ($h=0;$h<$number;$h++){ // no limit
if (!empty($match[$h][3]))
$text = sprintf("... %s<font
class='keyword'>%s</font>%s ...", $match[$h][1], $match[$h][3],
$match[$h][4]);
else{
//print_r($match);
}
}
}
--------8<----------------------------

There's the regex that looks through $portion, which is the strip_tags
version of the file's contents. And if I echo $portion right before
that line, I see the stripped code. However, when I get to the line
where it checks $match[$h][3] for the keyword that was searched for,
it craps out. Not 100% of the time, but most of the time. Im trying
to figure out details about these html pages, to no avail.
So as a result of failing that empty test, the entire html page is
dumped out as a search result.

Not being a regex expert, Ive had a hell of time troubleshooting. But
I feel the problem lies in there. Something with the regex not finding
the keyword correctly, or something.

Part Of The Script To Refresh With Out Refreshing The Entire ?
I am have a script, and in that script I have a section that pulls information from a database. I also have a drop down box that allows the user to slect which category they want the data to be pulled from. As of now, the way I have it, after they make a selection, the entire page gets refreshed and the new category is loaded. How can I make it that only that section of the script gets refreshed?

Showing Partial Row Info With Link To Entire Record
How can I show in the results just two or three fields of a record, with one of the fields linked to show the entire record?

Match Regular Expressions In A Webpage, Not The Entire Source
In order to check availability, I want to visit many different pages
from a database and try and match the regular expressions 'out of
stock' or 'unavailable' or 'sold out' etc. If found, the product will
be flagged as unavailable.

I tried using fopen() and preg_match() but the problem is, if the reg.
expression is present in javascript or in comments, the item gets
wrongly flagged. Is there a way of taking what appears on the users
screen, after parsing the page, and looking at it as a string I suppose
?

Paint An Opaque Layer Of Color Over An Entire Image?
Is there code (if so, what is it?) to paint an opaque layer of color over an entire image?

Delete Entire Line In Text File If Anything In The Line Matches Search String
how would I code a php script that would open a text file, look for a string i specified, and if it finds that string, it will delete the entire line in the text file that contained that text. I'm new to php, so sorry if this is really obvious..

Trying To Unset Single Session Variable Unsets Entire Session
I have all the data being stored in session variables, so when the student puts in his student ID, it passes it from one page to the next.  After the student votes, I use a function called logout that checks if the vote was counted, then uses session_unset($_SESSION['studentID']) and I also have a place that passes an error through session to let the user know of various problems with their login, such as if they have already voted.

if voting is disabled, or if there are no candidates to vote on.  The problem I am having is when I use session_unset, it unsets ALL session variables, not just the ones I want.  php.net says not to use session_unregister if register_globals is disabled, which it is.  What else can I do?  I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session.

Copy()
I'm trying to get this image upload function to work, and I'm stuck at a seemingly simple problem I can't solve. Here's the file with everything all-inclusive: Code:

Copy()
I am trying to copy an image to a directory. I got it working on its own, but can't get it working in the shopping cart admin area. any thoughts?

Copy Everything Between X And Y?
I'm trying to do what I figure is the opposite of preg_replace. I need to copy everything between two constant/known words in a string, e.g

$string = "I am going to the market to buy eggs and bacon for breakfast";
or
$string = "I am going to the market to buy fruit for breakfast";

How can I get 'eggs and bacon', or 'fruit', or whatever else is in between 'buy' and 'for breakfast'?

No Copy
Does anyone know how to make it to where no one can right click and copy a bunch of important data off of you page?

Copy A File From A Different Url
Hi

I am trying to copy a file froma different url but failing!

I am trying -

copy ("http://www.site.com/image.jpg" , "temp.jpg");

but getting an '

Unable to open 'http://www.olgaedwards.com/photos/2041.jpg' for reading: No such file or directory' error.

Strange because it exists and -

$file = fopen("http://www.site.com/image.jpg" , "rb");

works ok!

I even tried -

$file = fopen("http://www.site.com/image.jpg" , "rb");
copy ($file , "temp.jp");

But the same error.

Copy On Server
I think you haven't enough permission of your webserver is running. in iis an anoymous user is assigned when running a webserver. you need to change that user anoymous to a specific user and assigned that user in full permission to access your path. the system is running your php.exe ie php. so php.exe need to have full access to write or read that specific path. may be you havn't enough privilidge to read that path. check your systems security settings on this issue. apache2triad is a third party software i don't like to work in this env. try an exclusive machine and install php and webserver.

Here is the code.....

Copy A String
Im trying write a script that will do this:

I provide a directory location. The script scans all the files in a
directory, oldest to newest. In each file it looks for the word [QUOTE].
It counts forward until it finds [/QUOTE]. Then it copies the counted
characters. It opens a file titled quotes.txt and runs a scan to see if
that particular quote is in there. If it is not, it pastes it. If it is,
it drops that copied text and returns to the scan.

Im a bit stuck on the copy part. Once I find the text, how do I copy it?

Problem With Copy
I don't understand why this script want work

if($_POST['students'] == true)
copy("$file" , "/students/$file_name")
else echo "no check";

Parse error: parse error, unexpected T_ELSE

Copy From One Table To Another
I have some data in one mysql db table as such....

first_name | last_name | email | mail_type | gender | etc

I'd like to copy it into another mysql db table, but in a different order.....

id | email | first_name | last_name | gender | mail_type | etc

How would I do this with php ? A loop inserting values or something ?

Move_uploaded_file() Vs Copy()
Aside from the diffrences referenced in php.net is there anything different between copy() and move_uploaded_file() that would somehow alter uploaded files, .jpgs especially?

I have built an CMS that has worked fine for years. The public side is Flash. For certain reasons I have had to change my PHP to use move_uploaded_file() instead of copy(). Now any files I move with move_uploaded_file() make them unavailbe to Flash. When I check the server directories my .jpgs are where they are supposed to be and they are titled as expected. Also I am sure the uploaded .jpgs are not progressive.

Create/copy
what i want to do is have it when someone signs up it creates a folder with their username on the server and copyies files to that folder....


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