Jump to content

Archived

This topic is now archived and is closed to further replies.

skatermike21988

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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");

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.