Re: Move file to (potentially) non-existent directory
- From: gordonb.hex6t@xxxxxxxxxxx (Gordon Burditt)
- Date: Fri, 05 Sep 2008 21:17:13 -0500
I would like to do the following:
rename('/home/testfile.txt', '/home/to/a/potentially/non-existent/
directory/testfile.txt');
PHP apparently won't auto-create the directory structure if it doesn't
already exist on the file system. Instead, it throws an error when
the directory doesn't already exist, stating "No such file or
directory".
Does anyone know of a way around this?
Check if the directory structure exists (is_dir(), stat(), filetype(),
or whatever), and if not, create it (mkdir). You may want to make
this recursive (e.g. if you want to create /a/b/c/d/e/file.txt, check
/a/b/c/d/e, and if it doesn't exist, check /a/b/c/d before trying to
create /a/b/c/d/e.) As of PHP 5.0.0, mkdir() accepts a recursive flag
so you don't need to code the recursive stuff.
You might run into permission problems and find this impossible.
.
- Follow-Ups:
- Re: Move file to (potentially) non-existent directory
- From: C. (http://symcbean.blogspot.com/)
- Re: Move file to (potentially) non-existent directory
- References:
- Prev by Date: Move file to (potentially) non-existent directory
- Next by Date: Re: Help needed
- Previous by thread: Move file to (potentially) non-existent directory
- Next by thread: Re: Move file to (potentially) non-existent directory
- Index(es):
Relevant Pages
|