开发者

PHP FILE HANDLING ERROR - Unable to figure out [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.
function Random_N() {
    $RandomNumber = mt_rand(1, 9开发者_StackOverflow中文版999); 
    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;


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.


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';


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'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜