0

Yes, I know my title is a bit confusing. Anyway, I have a PHP file, which I want to drop another PHP file, and the dropped PHP file would check if the creator exists, and if it doesn't it deletes files, how could I do this? I know how to drop a text file with some content in it, but not a much more complicated PHP file with multiple lines.

Is there anyway to do this?

4
  • 1
    Not only your title is confusing to me. Could you give an example of what you are trying to do? And clarify what "drop" means in this context? Commented Sep 1, 2016 at 13:53
  • Clearly confusing by htis line "the dropped PHP file would check if the creator exists" ---- what it mean "if the creator exists, and if it doesn't it deletes files" Commented Sep 1, 2016 at 13:58
  • @simon drop = create | I want the created php file to check if the creator still exists, and if it doesn't, it does an action (e.g delete files) Commented Sep 1, 2016 at 14:08
  • I see. Parziphals answer does exactly what you want Commented Sep 1, 2016 at 14:31

1 Answer 1

1

Assuming that with "drop" you mean "create", this would work:

File parent.php:

<?php

// Child destination
$childFile = __DIR__ . '/child.php';

// Full path to this parent file
$file      = __FILE__;

// Child contents
$contents = <<<EOT
<?php

if (!is_file('${file}')) {
    // Parent doesn't exist; delete some files and exit
    // unlink(...);
    exit;
}

// Parent exists; keep doing something else
echo "I'm the child!";

EOT;

// Create child file
file_put_contents($childFile, $contents);

// Do something else...
echo "Created child";

The parent creates a child file, where the existance of the parent is checked; if it doesn't exist, the child will do something else and then exit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.