I have a file called
I want to move the
After a bit of searching I saw that you can move a file using the
After adding the
index.php
(located in the root folder of the website) which creates a file called cat.php
in the root folder of the website.
PHP:
<?php
$title = "cat";
$image = "cat_pics";
$desc = "funny cat pictures";
$content = "<?php include '_data/head.php'; ?><title>" . $title . " | Crazy Chicken Girl</title><?php include '_data/header.php'; ?><?php echo 'Title: " . $title . "'; echo '\nImage: " . $image . "'; echo '\nDescription: " . $desc . "'; ?><?php include '_data/footer.php'; ?>";
$newfile = fopen($title . ".php", "w");
fwrite($newfile, $content);
fclose($newfile);
?>
I want to move the
cat.php
file to a folder and rename the file index.php
, so that the file path will be /cat/index.php
.After a bit of searching I saw that you can move a file using the
rename()
function, so I added this to my code:
PHP:
$path = $title . ".php";
$newpath = $title . "/index.php";
rename($path, $newpath);
After adding the
rename()
function, I have this code, but the rename()
function doesn't seem to move the file.
PHP:
<?php
$title = "cat";
$image = "cat_pics";
$desc = "funny cat pictures";
$content = "<?php include '_data/head.php'; ?><title>" . $title . " | Crazy Chicken Girl</title><?php include '_data/header.php'; ?><?php echo 'Title: " . $title . "'; echo '\nImage: " . $image . "'; echo '\nDescription: " . $desc . "'; ?><?php include '_data/footer.php'; ?>";
$newfile = fopen($title . ".php", "w");
fwrite($newfile, $content);
fclose($newfile);
$path = $title . ".php";
$newpath = $title . "/index.php";
rename($path, $newpath);
?>
Last edited: