Forum Moderators: coopster

Message Too Old, No Replies

Open and Write to a new file

         

d40sithui

2:56 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



hey guys, got a strange issue. i want to create a new file and attach it to an email. so far, im stuck with opening a new file and writing to it. heres my script. I always get the "Cannot open file error. what am i doing wrong?

<?
$today = date("mdY");
$file_to_send =$today."order.xls";

$output = "something";

if(!$handle2 = fopen($file_to_send, 'w+')){
echo "Cannot open file<br>\n";
}
if(fwrite($handle2, $output)==false){
echo "Cannot write to file<br>";
}

fclose($handle2);

?>

darrenG

3:47 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



Possibly a permissions issue? Do you have write permissions set for the target directory?

whoisgregg

3:55 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've always found I need to set the full path... Something like "/var/www/html_public/whatever/some_file_name.txt" as opposed to just "some_file_name.txt"

You can use $_SERVER['DOCUMENT_ROOT'] to get the path to the root of your site.

d40sithui

4:26 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



yea it was des a permission issue. whats the lowest setting for it to work properly. i currently have it as chmod 777

darrenG

7:09 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



757 I think..