Help with creating a .PHP file and storing it!

Okay, I am fairly new to PHP…

I am looking how to create a .PHP document with a md5 name. I already have a script to it, but I cant figure out how to make it. I have it set to write the document created, just I cant figure out how to create it and have it uploaded to my server. Heres what I have:

<?php

$submit = $_POST['submit'];

if ($submit)
{
$newName = 'test/' . substr(md5(rand() . time()), 0, 20) . '.php';
    $tf = fopen($newName, 'w');
	fwrite($fp, '<html><head><title>Hello</title></head><body><p>Hello People!</p></body></html>');
    fclose($tf);
    move_uploaded_file($_FILES['imagedata']['tmp_name'], $newName);
// Website
    echo 'http://www.linkremoved.com/' . $newName;
}
else
{
echo "<form action='md5createtest1.php' method='post'><input type='submit' value='Submit' name='submit' /></form>";	
}

?>

But after I try it… I get this error:

Warning: fopen(test/5ac397dc440982c9e63b.php) [function.fopen]: failed to open stream: No such file or directory in /home/removed/public_html/test/md5createtest1.php on line 8

Warning: fwrite(): supplied argument is not a valid stream resource in /home/removed/public_html/test/md5createtest1.php on line 9

Warning: fclose(): supplied argument is not a valid stream resource in /home/removed/public_html/test/md5createtest1.php on line 10
http://www.linkremoved.com/test/5ac397dc440982c9e63b.php

Any help?

You’re going about it the wrong way. $tf either needs to be $fp or vise versa, can’t open a file that does’t exist :slight_smile: What’s opened with fopen needs to match what’s in fwrite().

You don’t need to use move_uploaded_file(), there’s no file input that i can see.
[php]

<?php if(isset($_POST['submit'])) { $newName = "test/".substr(md5(rand(0,100).time()),0,20).".php"; $fp = fopen($newName, 'w'); $contents = " Hello

Hello People!

"; fwrite($fp, $contents); fclose($tf); echo 'http://www.linkremoved.com/' . $newName; } else { echo " "; } ?>[/php]

[/php]

With your code, I notice that your doing the same thing I am… Write a file that doesnt exist, which is my error, I have also tried using X instead of W to create the file, but I am having no luck. Also in your code, $contents would be undefined because you didnt write it anywhere except in the code, and I never had it originally…

-Improvizionz

Sponsor our Newsletter | Privacy Policy | Terms of Service