Author Topic: Help with creating a .PHP file and storing it!  (Read 205 times)

Improvizionz

  • Guest
Help with creating a .PHP file and storing it!
« on: March 10, 2012, 11:33:27 PM »
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:

Code: [Select]
<?php

$submit 
$_POST['submit'];

if (
$submit)
{
$newName 'test/' substr(md5(rand() . time()), 020) . '.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:

Code: [Select]
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?

richei

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1136
  • Karma: 23
    • View Profile
Re: Help with creating a .PHP file and storing it!
« Reply #1 on: March 11, 2012, 03:52:59 AM »
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 :)  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 Code: [Select]

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

[/php]

Improvizionz

  • Regular Member
  • **
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Help with creating a .PHP file and storing it!
« Reply #2 on: March 12, 2012, 07:50:30 PM »
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