读取php文件
reading in a php file
我已经从svn下载了文件,这些文件现在存储在本地磁盘上的文档中。这些文件大多是php文件。我如何读取位于本地磁盘上的文档(不是"txt"),并在使用php的网站上打开它们。到目前为止,这就是我所拥有的,
index.php
$(function() {
$('#getData').click(function(event) {
event.preventDefault();
$.ajax({
type: "GET",
url: "endPoint.php",
data : { field2_name : $('#userInput2').val() },
beforeSend: function(){
}
, complete: function(){
}
, success: function(html){
//this will add the new comment to the `comment_part` div
$("#displayParse").html(html);
//$('[name=field1_name]').val('');
}
});
});
});
</script>
<form id="comment_form" action="endPoint.php" method="GET">
Enter the file you would like to view:
<input type="text" class="text_cmt" name="field2_name" id="userInput2"/>
<input type="submit" name="submit" value="submit" id = "getData"/>
<input type='hidden' name='parent_id' id='parent_id' value='0'/>
</form>
<div id="displayParse">
</div>
endPoint.php
<?php
$filePath = $_GET["field2_name"];
$url = "cs242_final/home/" . $filePath;
$file = fopen($url, "r");
fread($file,filesize($url));
echo '<div class="comment">' . $file . '</div>';
?>
基本上,用户输入一个他们想要打开的文件,这些文件位于我的本地磁盘上。不确定哪里出了问题,因为文件内容没有打印出来。此外,我正在使用MAMP在localhost上运行我的代码。我使用的IDE是phpstorm。我不确定我的文档是否需要加载到phpstorm上才能访问它们
您没有将fread($file,filesize($url));
的值分配给任何东西。尝试:
$contents = fread($file,filesize($url));
echo '<div class="comment">' . $contents . '</div>';
此外,如果在生产环境中使用此方法,请确保正确地转义文件名的用户输入,否则可能会发生不好的事情。
相关文章:
- 如何在php文件中获取$.post-ajax传递的值
- Javascript运行php文件,然后下载文件
- 通过Ajax将JavaScript函数传递给PHP文件
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 通过ajax到php文件获取单选按钮值
- 每天用javascript包含不同的php文件
- 如何使用javascript调用Php文件
- 如何使用php文件中的GET来获取我在.js文件中声明的变量
- 在CodeIgniter视图中将Javascript或jQuery代码作为PHP文件编写可以吗
- CORS:否'访问控制允许来源'header-但是php设置头文件
- 用PHP发送html表单和文件附件
- 动态地包含来自外部文件PHP的JavaScript
- 向文件 php 表单提交添加多个输入
- 将web服务响应转换为PDF文件- PHP, Javascript
- 基于XML文件(PHP, Jquery)的页面生成
- 如何使用jQuery.ajax发送请求到文件php
- 显示数据下拉列表从另一个文件(php,mysql,javascript)
- 两个电子邮件在同一个文件php
- 从mysql中存储和检索用户js文件.php
- 组织3个文件:PHP、HTML、JS和Smarty