Jump to content


Photo

Making a new folder and copying a file over and edit it


  • Please log in to reply
9 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 06:11 AM

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.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 September 2006 - 06:35 AM

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

#3 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 07:51 AM

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

#4 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 05 September 2006 - 09:19 AM

any idea why my php coding is turning into html once the file has been copied?

#5 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 September 2006 - 09:53 AM

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");

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 07 September 2006 - 05:44 AM

Sorry i took so long for a reply, but here is my 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";
}

Hope that helps

#7 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 07 September 2006 - 06:47 AM

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.

#8 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 September 2006 - 08:21 AM

I personaly would do something like this. Are you attempting to open a remote websites index.php file?

<?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);
?>

Now this is a little sloppy but it should give you the basic idea.

Good luck,
Tom
 


Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#9 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 07 September 2006 - 06:57 PM

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 51

Warning: fopen(../$url/index.php): failed to open stream: No such file or directory in /home/friends/public_html/test/set_url.php on line 52
unable to create the requested file

#10 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 07 September 2006 - 07:58 PM

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??




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users