0

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();
if(!$Query)
{
    die("There was an error creating your product!");
}
else
{
    echo "Yes! Your product was created, I hope " . $Title . " will rank high!";
    $Insert_Link_Click = '0';
}

$php = "<?php

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

if(!mysql_select_db('FinddOnline'))
{
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!\");
}
else
{
header(\"location:$url\");
}
                      

?>";

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

?>
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by nonshatter
-1

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

0

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

0

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.