josephman1988 Posted August 27, 2008 Share Posted August 27, 2008 ... in one form. Hi guys, On submission of the form, it creates a directory named by the title that is inputted. Everything works fine, but upon submission i want to copy a file from 1 directory and copy it to the newly created directory. Here was my attempt: $titlereplace = $_SERVER['DOCUMENT_ROOT'].'/'; $titlereplace .= str_replace(' ', '-', $gTitle); $titlereplace .= '/'; $old = umask(0); $makedir = mkdir($titlereplace, 0777); umask($old); $file = $_SERVER['DOCUMENT_ROOT'] . '/includes/details.php'; $dest = $titlereplace; if (!copy($file, $dest)) { print 'Did not copy'; } However the basic error of 'directory doesn't exist' occurs, and I don't know how to fix it. Thanks for any help =] Link to comment https://forums.phpfreaks.com/topic/121550-creating-dir-copyingmoving-file/ Share on other sites More sharing options...
obsidian Posted August 27, 2008 Share Posted August 27, 2008 You are trying to write to the /includes directory off the doc root, so you need to be sure that directory exists before you write to it: <?php $dir = $_SERVER['DOCUMENT_ROOT'] . '/includes/'; if (!file_exists($dir)) { if (FALSE === mkdir($dir, 0775)) { die('Could not create directory!'); } } // Directory is now created, so move your file ?> Link to comment https://forums.phpfreaks.com/topic/121550-creating-dir-copyingmoving-file/#findComment-626897 Share on other sites More sharing options...
josephman1988 Posted August 27, 2008 Author Share Posted August 27, 2008 Im not trying to write to the includes am I? Im trying to pull the file from the includes to the newly created directory .. or am I clueless? Would this be right or don't I get it? $titlereplace = $_SERVER['DOCUMENT_ROOT'].'/'; $titlereplace .= str_replace(' ', '-', $gTitle); $titlereplace .= '/'; $old = umask(0); $makedir = mkdir($titlereplace, 0777); umask($old); $file = $_SERVER['DOCUMENT_ROOT'] . '/includes/details.php'; if (!file_exists($file)) { if (FALSE === mkdir($file, 0775)) { die('Could not create directory!'); } } copy($file, $titlereplace); -- PS: Yay at your Vivi avatar xD -- Link to comment https://forums.phpfreaks.com/topic/121550-creating-dir-copyingmoving-file/#findComment-626921 Share on other sites More sharing options...
obsidian Posted August 27, 2008 Share Posted August 27, 2008 My bad. I took a cursory glance at it, and I misinterpreted what it was you are doing. I would just do the same check on the $titlereplace location before you try to write it. Also, the user executing the script has to have write access to the directory on the server. Check the location to which you are writing the directory as well for user permissions. Link to comment https://forums.phpfreaks.com/topic/121550-creating-dir-copyingmoving-file/#findComment-626929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.