skatermike21988 Posted September 5, 2006 Share Posted September 5, 2006 ok, i am wanting to make a script to create a new folder and copy a file over and have certain spots of the file edited to meet some specific things,If anyone can atleast help me with the part of making the directy and having it chmod, and how to copy a file from one directory to the new one. I should then be able to handle it. Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/ Share on other sites More sharing options...
zq29 Posted September 5, 2006 Share Posted September 5, 2006 You can create a directory with the mkdir() function - If I remember correctly, it's second parameter can be used to chmod the directory at the same time. You can copy files with the copy() function. For more info onhow to use them, check out the manual over at php.net Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-86192 Share on other sites More sharing options...
skatermike21988 Posted September 5, 2006 Author Share Posted September 5, 2006 ok, i have it now where it makes the new directory and copies the file, but for some reason, my file is written in php but when it's copied it is becoming html Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-86216 Share on other sites More sharing options...
skatermike21988 Posted September 5, 2006 Author Share Posted September 5, 2006 any idea why my php coding is turning into html once the file has been copied? Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-86234 Share on other sites More sharing options...
zq29 Posted September 5, 2006 Share Posted September 5, 2006 Care to post up your code? The only way I think this can happen is if you have a type in the destination parameter like:copy("path/to/source/script.php","path/to/destination/script.html"); Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-86239 Share on other sites More sharing options...
skatermike21988 Posted September 7, 2006 Author Share Posted September 7, 2006 Sorry i took so long for a reply, but here is my code:[code]$set=$_REQUEST[set];if ($set=='url') {$url=$_POST[url];mkdir("../$url", 0707);mkdir("../$url/include", 0707);$file = 'http://www.friendshideout.com/test/copy/index.php';$newfile = 'temp/index.php';copy($file, $newfile);$file2 = 'http://www.friendshideout.com/test/copy/include/db.php';$newfile2 = 'temp/include/db.php';copy($file2, $newfile2);$file1 = 'http://www.friendshideout.com/test/copy/include/header.php';$newfile1 = 'temp/include/header.php';copy($file1, $newfile1);$sql="UPDATE `users` SET `url` = 'http://www.friendshideout.com/$url' WHERE username='$username'";mysql_query("$sql") or die (mysql_error()); echo "Congratulations Your New Url Is: http://www.friendshideout.com/$url";}[/code]Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-87578 Share on other sites More sharing options...
zq29 Posted September 7, 2006 Share Posted September 7, 2006 My guess is that this is happening because you're trying to copy an already processed file. Try using relative paths instead of absolute paths for your source files. Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-87587 Share on other sites More sharing options...
tomfmason Posted September 7, 2006 Share Posted September 7, 2006 I personaly would do something like this. Are you attempting to open a remote websites index.php file?[code]<?php$set=$_REQUEST[set];if ($set=='url') {$url=$_POST[url];if (!is_dir("../$ur")) { mkdir("../$url", 0707);}if (!is_dir("../$url/include")) { mkdir("../$url/include", 0707);}$file = 'http://www.friendshideout.com/test/copy/index.php';$newfile = 'temp/index.php';$handle = fopen($file, "rb");if (!$handle) { echo "Unable to open $file."; include("somepage.php"); exit();}$contents = fread($handle, filesize($file));$fp = fopen($newfile, "x+b");if (!$fp) { echo "unable to create the requested file"; include("somepage.php"); exit();}fwrite($fp, $contents);fclose($handle);fclose($fp);?>[/code]Now this is a little sloppy but it should give you the basic idea. Good luck,Tom Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-87602 Share on other sites More sharing options...
skatermike21988 Posted September 7, 2006 Author Share Posted September 7, 2006 Ok, i have tried that code and these are the errors i am recieving, now i am not very familiar with this so i can't exactly go through and debug it myself but the errors are:Warning: Wrong parameter count for fread() in /home/friends/public_html/test/set_url.php on line 51Warning: fopen(../$url/index.php): failed to open stream: No such file or directory in /home/friends/public_html/test/set_url.php on line 52unable to create the requested file Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-87914 Share on other sites More sharing options...
skatermike21988 Posted September 7, 2006 Author Share Posted September 7, 2006 ok, i have solved this issue, now for the file that is copied, ok what it does is it takes that new folder that was created and stores it in a database, that url is specific to a registered user, now i need to get the page that was copied to when that url is typed in pull the data from the database from that url.catch what i'm saying or is it confusing?? Quote Link to comment https://forums.phpfreaks.com/topic/19741-making-a-new-folder-and-copying-a-file-over-and-edit-it/#findComment-87952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.