0

抱歉,如果这是重新发布,但我在用 PHP 将文件写入磁盘时遇到了一些困难。我正在尝试使用 HTML 表单上传文件,然后使用 PHP 文件将该文件下载到我的计算机,但我不断收到错误消息

Warning: fopen(temp/127.0.0.1): failed to open stream: Permission denied in C:\xampp\htdocs\VotingBox\processForm.php on line 30

我已经尝试chmod对该目录赋予自己写入权限,并且该目录是在 Windows 7 中的管理员配置文件下创建的,因此它应该具有文件写入功能,但我仍然遇到相同的错误。这是我编写文件的代码:

$ip=$_SERVER['REMOTE_ADDR']; 
if(is_dir("temp/".$ip) == false)
{
    mkdir("temp/".$ip, 0777);
}
chmod("temp/".$ip, 0777);
move_uploaded_file($candImgs[$i], "temp/".$ip);
$filename1 = "temp/".$ip; 
$fp1 = fopen($filename1, "r");
$contents1 = fread($fp1, filesize($filename1)); 
fclose($fp1); `

任何帮助将不胜感激。另外,如果有帮助的话,我正在使用 XAMPP 来托管我的文件。

4

1 回答 1

0

I finally realized that the problem was with my HTML form, and not with the php code. Here are the useful parts of my final code if anyone else has this problem:

<form name="FORM_NAME" enctype="multipart/form-data" method='post' action="ACTION">

<input type="hidden" name="MAX_FILE_SIZE" value="170000" />

And finally my php code:

    move_uploaded_file($_FILES['fileName']['tmp_name'], $target_path);  
    $fp      = fopen($target_path, 'r');
    $data = fread($fp, filesize($target_path));
    fclose($fp);
    $encoded = chunk_split(base64_encode($data)); 
于 2013-04-27T23:18:16.087 回答