Re: Cannot copy a file to a dynamic folder

From: Date: Tue, 31 Jul 2001 09:09:16 +0000
Subject: Re: Cannot copy a file to a dynamic folder
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60365@lists.php.net to get a copy of this message
> // Make new directory function > $default_dir = ("D:\www\Proj\$textfield2\"); The ()'s are silly... They force the string to be evaluated before any other expressions in this statement, and there aren't any. The \'s are bad, though. \ is a "special" character inside of " and you need to put \\ to get one \. So, this line should be: $default_dir = "D:\\www\\Proj\\$textfield2\\"; An alternative is to just / like a real OS :-) $default_dir = "D:/www/Proj/$textfield2/"; Can't guarantee the trailing slash belongs there or not. You'll have to try both ways to be sure. > if(file_exists($default_dir)) rmdir($default_dir); This is technically okay, but sooner or later, you're going to need to do more than just rmdir. I'd recommend using: if(file_exists($default_dir)){ rmdir($default_dir); } > mkdir($default_dir, 0777); Logically, it might be better to test if the directory does *NOT* exist, then make it. Thus replace these two (well, four lines, now) with: if (!file_exists($default_dir)){ mkdir($default_dir); } NOTE: This will puke if D:\\www\\Proj doesn't already exist... You may want to add some error checking such as: if (!file_exists($default_dir)){ if (!mkdir($default_dir)){ echo "Could not create $default_dir. Parent directory probably doesn't exist."; } } > // Copy template.html to new directory > $filename = D:Automator\auto_2\Template.html; You need quotes and \\ for each \ and you are missing a \ after D: $filename = "D:\\Automator\\auto_2\\Template.html"; > copy($filename, ($default_dir) .overview.html); You need quotes around the overview.html part: copy($filename, ($default_dir) . "overview.html"); You may want to alter you php.ini file and use E_ALL (including E_NOTICE) instead of the default setting -- A lot of the errors you are making would be more clear if you did that. > Can I not have these two scripts run together? The mkdir function alone > works. Can someone tell me what I'm doing wrong? I think I hit everything, but you never know for sure until it actually works, eh? -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#60365) next »