PDA

View Full Version : writting files



bluewalrus
10-23-2008, 02:46 AM
I don't have any code for this just a question. Can php write to an html file thats on a server. Right now i'm writing to a txt file then having the other html page open the text file and echo the contents. Also is there a way to create a text file with php. I've seen the 'x+' and the 'w+' on the fopen and everything i've seen says attempts to write to the file I don't get why it says attempt why not just do it and if it can't why not say it just writes to it and not mention creating the file.

Thanks for ideas or comments.

Nile
10-23-2008, 02:56 AM
I don't exactly get what you want. Do you want to have a php file write to another php or html file. Do you wanna know what the x+, w+, a+, blahs and blahs do? Do you want to know how to make a file? Do you want to know why it attempts instead of just doing? Here:

Writing to another php file, or a html file, is simple. You do the same thing you do when writing to a txt file. Although to get it to go where you want it in the html file is a bit more difficult.

All of the operators do different things. I would explain what they do. But I don't know by heart, I just peak at a cheat-sheet every single time I code something that is in need of that kinda code. So here are some help pages:
http://www.w3schools.com/PHP/php_file.asp
http://www.tizag.com/phpT/fileopen.php

It attempts instead of directly doing it for a few reasons. 1) It needs to see if its possible, for example it needs to see if this is on its domain, or someone elses. If its on someone elses, then it will return an error. 2) It needs to check the file permissions, for the folder, its own file, and the file its getting info from. For example I think that the file needs to be set to 777 CHMOD. But I don't know. 3) It needs to see if it gets the correct data.
If it doesn't, then it will return an error.

I hope this post helps you,
Nile

bluewalrus
10-23-2008, 04:46 AM
I get these messages:


Warning: fopen(video22.html): failed to open stream: Permission denied in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 44

Warning: fwrite(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 45

Warning: fclose(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 46
When I put this code in:

$File = "video22.html";
$Handle = fopen($File, 'x+');
fwrite($Handle, $pfile);
fclose($Handle);

also I've tried it as a txt file and a html. It doesn't make a difference, the directories set as 777, the file is not but can't be because it's suppose to be being created. This is on my own domain.

Nile
10-23-2008, 11:39 AM
Show me line 44, 445, 46 I suppose there is one because it gives an error about line 44, 45, 46 above where you posted, and here:
http://bluewalrus.net/testing.php

bluewalrus
10-23-2008, 01:44 PM
$Handle = fopen($File, 'x+');
fwrite($Handle, $pfile);
fclose($Handle);
?>


Thanks

NXArmada
10-23-2008, 01:49 PM
Is the file chmod writeable 777

bluewalrus
10-23-2008, 04:31 PM
its suppose to be creating the file there is no file yet. the directory is 777

NXArmada
10-23-2008, 05:20 PM
i had a sim problem and this worked for me:



fopen($myFile, 'a+r+w+x+')

bluewalrus
10-23-2008, 05:25 PM
brings up the same errors

NXArmada
10-23-2008, 05:30 PM
what is
$pfile mapping too??

bluewalrus
10-23-2008, 05:36 PM
It holds a bunch of xml.

if ($all === "all" ) {
$pinclude = $top . $vvfile . $sspeechfile . $prfile;
$vinclude = $top . $sspeechfile . $ppfile . $prfile;
$sinclude = $top . $vvfile . $ppfile . $prfile;
}
if ($bp === "Yes") {
$pfile = $pincluded . $pfile . '<h4>The "Big Picture"</h4><p>View a panoramic picture of the event.&#160;</p><table width="100%"><tbody><tr><td>&#160;<a title="" href="Agov3/images/' . $event . '_bp.jpg" rel="lightbox[roadtrip]"><img title="A panoramic view of the event." alt="A panoramic view of the event." src="/Agov3/images/' . $event .'_bplk.jpg" border="0" /></a></td></tr></tbody></table><br />';
}
else
{
$pfile = $pincluded . $pfile;
}
for ( $num = 1; $num <= $maxnum; $num++ )
{
$pfile = $pfile . '<p>Click photo to open larger version.&#160; Right-click photo to download and save.<br /></p><table bordercolor="#c0c0c0" cellpadding="2" width="100%" border="1"><tbody><tr><td><a title="Info about photo" href="Agov3/images/' . $event . $num . 'lb.jpg" rel="lightbox[roadtrip]"><img title="Info about photo" height="133" alt="Info about photo" src="/Agov3/images/' . $event . $num . 'lk.jpg" width="200" border="0" /></a><center><a href="Agov3/images/' . $event . $num . 'web.jpg" target="_blank">Full Res</a></center></td><td>Info about photo</td></tr></tbody></table>';
}

bluewalrus
10-26-2008, 02:28 PM
any other ideas?