プロが教える店舗&オフィスのセキュリティ対策術

はじめまして。
このたび業者さんにホームページを自分で更新できるプログラムを作って頂きました。
今まではさくらインターネットで使用していたのですが、今回ロリポップにしたところ、更新すると次のようなエラーが出てしまいます。


Warning: fopen(./data/news_08.txt) [function.fopen]: failed to open stream: Permission denied in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 23

Warning: flock(): supplied argument is not a valid stream resource in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 24

Warning: fputs(): supplied argument is not a valid stream resource in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 26

Warning: chmod() [function.chmod]: Operation not permitted in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 27


エラーを見てもさっぱりなんですが、解決方法などがわかる方いらっしゃいますでしょうか?

どうかよろしくお願致します。

A 回答 (4件)

27行目の


chmod($filename, 0666);

# chmod($filename, 0666);
としてみてください。
もしくは、
chmod($filename, 0707);;
ですかね?
    • good
    • 0
この回答へのお礼

ありがとうございます!

# chmod($filename, 0666);
としたところ無事機能しました!

本当に本当にありがとうございました!

お礼日時:2008/03/26 19:42

phpファイルは604


news_08.txtを書き込むdataディレクトリが707

edit.phpの上から7行目にchmodがあると思いますが
実際はどのようなコーディングなのでしょうか?

また、dataディレクトリの中には既にnews_08.txtなどがあるのでしょうか?

この回答への補足

<?php

$id = $_GET['id'];
$mode = $_POST['mode'];
$news = $_POST['news'];

$title = "更新";

if ($id == 0) { $title = "新着情報"; }
else { $title = $title . $id; }

$filename = "./data/news_" . sprintf("%02d", $id) . ".txt";

$message = "";

if ($mode == "update") {
$writedata = $news;
$writedata = str_replace("\r\n","\n", $writedata);
$writedata = str_replace("\r","\n", $writedata);
$writedata = str_replace("\n","<br>", $writedata);
$writedata = stripslashes($writedata);

$fp = fopen("$filename", "w");
flock($fp, LOCK_EX);
fputs($fp, $writedata);
fclose($fp);
chmod($filename, 0666);

$message = "<p><font color=blue><b>更新しました。</b></font></p>";
}

if (file_exists($filename)) {
$fp = @fopen($filename, "r");
$readdata = "";
while (!(feof($fp))) {
$buf = chop(fgets($fp, 1024));
if (!$buf) { continue; }
$readdata .= $buf;
}
fclose($fp);
}

$news = $readdata;


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio …
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
<title><?= $title ?></title>
</head>

<body bgcolor="#F3F3F3">
<form name="frmMain" method="post" action="<?= $editscript ?>">
<input type="hidden" name="mode" value="update">
<p>■<?= $title ?></p>
<?= $message ?>
<p align="center">
<textarea name="news" cols="80" rows="15" wrap="virtual" id="news"><?= str_replace("<br>", "\n", $news) ?></textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value=" 更 新 ">
</p>
</form>
</body>
</html>

補足日時:2008/03/26 18:41
    • good
    • 0
この回答へのお礼

たびたびのご回答ありがとうございます。
プログラミングについてまったく知識がなく念のためすべてのコーディングを投稿させていただきました。

さくらインターネットでは使用できていたので、問題はないと思ったのですが、パーミッション以外にもなにか問題があるのでしょうか?

どうかよろしくお願致します。

お礼日時:2008/03/26 18:43

http://lolipop.jp/?mode=manual&state=hp&state2=p …
に詳しく書いてあると思います。
news_08.txtは書き込む必要があるディレクトリではないでしょうか。
また、CGIを動作させているのはウェブサーバであって、
契約者のアカウントとは別物と考えます。
そうすると、dataディレクトリのパーミッションは、707または777
となるのではないでしょうか。

以上、よろしくお願いします。

この回答への補足

早速試してみたところ、
再度の行の
Warning: chmod() [function.chmod]: Operation not permitted in /home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/edit.php on line 27

だけが残ってしまいました。
他の行はすべて消えたので、あと少しだとは思うのですが・・・

ファイルは
editフォルダの中に
edit.phpが1つ(604)
編集の為のhtmlファイル(707に設定)
dataフォルダ(中身もすべて707)
別ファイルでnewsread.phpというのがあったのですがこちらも604に設定したのですが、ダメでした・・・

何度も本当に申し訳ございませんが、どうかよろしくお願致します。

補足日時:2008/03/26 14:25
    • good
    • 0
この回答へのお礼

ありがとうございます。

早速試してみます。
本当にありがとうございます。

ちなみにphpデータのパーミッションは604のままでよろしいのでしょうか?
何度もすみません。

お礼日時:2008/03/26 14:22

/home/sites/lolipop.jp/users/lolipop.jp-dp16027581/web/edit/data


ディレクトリのパーミッションはどうなっているのでしょうか?
おそらく、書き込み権限が無いように思われます。
    • good
    • 0
この回答へのお礼

早速の解答ありがとうございます。

http://lolipop.jp/?mode=manual&state=hp&state2=cgi

こちらのページを参考にしてパーミッションは「604」で設定しています。

お手数ですが、どうかよろしくお願致します。

お礼日時:2008/03/26 13:54

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!