The code was designed to create a new page with the random number and then it would insert code into the newly created file. This worked when I was using my localhost, but now I receive these error messages. I looked around the web and I saw somethings about permissions??? So, please be as detailed as possible in your answer!
I get this error for this code.....

Warning: fopen(964830301.php) [function.fopen]: failed to open stream: Permission denied in product.php on line 168
PHP Error Message
Warning: fwrite(): supplied argument is not a valid stream resource in product.php on line 169

This is the code...

$Random_Number = rand(100,100000000000);
$Check_Number = mysql_query("SELECT * FROM products WHERE randomnumber='$Random_Number'");
$Check_Final = mysql_num_rows($Check_Number);

while($Check_Final != '0')
    $Random_Number = rand(100,100000000000);

$Query = mysql_query("INSERT INTO products (title,url,finalurl,category,owner,shortdescription,price,rank,tag1,tag2,tag3)
                      VALUES ('$Title','$Random_Number','$url','$Category','$Username','$SD','$Price','-10','$Tag1','$Tag2','$Tag3')");
echo mysql_error();
    die("There was an error creating your product!");
    echo "Yes! Your product was created, I hope " . $Title . " will rank high!";
    $Insert_Link_Click = '0';

$php = "<?php

if (!mysql_connect(\"\",\"root\",\"\"))
  die(\"MySQL could not connect!\");

die(\"My SQL could not select Database!\");
\$Today = date(\"Y-m-d\");
if(!mysql_query(\"INSERT INTO clicks (username,title,date)
                      VALUES ('$Username','$Title','\$Today')\"))
    die(\"Opps Try again!\");


$Create_File = fopen($Random_Number . '.php','w');

7 Years
Discussion Span
Last Post by nonshatter

Okay, the error your getting means that fopen can't open the file you're requesting because the permissions of that file (or directory) won't allow it.

If you're server is on Linux:
From the shell cd to the directory where that file resides, and issue

chmod 777 *

This will give you full read/write/execute permissions to all files in the directory, and prevent the error from occurring again.

If you're running your site from a web host, check with them for how to change your permissions.

Edited by nonshatter: n/a


Okay, go to your FTP access to browse your directories, then in the left panel there should be a link for permission settings. Tick all the boxes


Go to your cPanel, under the Files tab click 'Another File Manager'. Click through public_html directory, click a file or directory ONCE, then in the left panel there IS a permissions option. I'll leave it up to you to decide which files you will want to use file handles on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.