tags:

views:

27

answers:

3
function Random_N() {
    $RandomNumber = mt_rand(1, 9999); 
    return 'temp_file/$RandomNumber.html';
}

global $file_name;
$file_name=Random_N();          


$file = fopen($file_name, 'w+');
$text=$msg1;
fwrite($file, $text);

$_SESSION['body']=$msg1;
$_SESSION['file_name1']=$file_name;
A: 

Ok, for starters - some explanation about the problem is much appreciated. You'll find you will get a lot more assistance if don't just expect everyone to read your code and determine for themselves what you're trying to do.

In your code, this line: $text = $msg1 might be a source of your problem. Where did $msg1 come from?

In the Random_N function, it will always return the string 'temp_file/$RandomNumber.html' because it is enclosed in single quotes. Either change to double quotes, or preferably, use some concatenation:

return 'temp_file/' . $RandomNumber . '.html';
nickf
A: 

You made a mistake i think so, see this function

function Random_N() {
$RandomNumber = mt_rand(1, 9999); 
return 'temp_file/$RandomNumber.html';
}

$RandomNumber is a variable. return function you used will not return the correct value it return value for $RandomNumber.html. Concatenate correctly.

instead of return 'temp_file/$RandomNumber.html'

type return 'temp_file/'.$RandomNumber.'.html'

RSK
+1  A: 
function Random_N() {
$RandomNumber = mt_rand(1, 9999); 
return "temp_file/$RandomNumber.html";
}

Try above, you had put a variable inside single quotes which has no effect.

Sarfraz