我试图上传html文件,当我上传我想要他的显示在iframe或对象。
HTML
<form id="myForm" action="accept-file.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<br>
<div class="col-sm-1"></div>
<input type="submit" value="Load File" />
</form>
<object width="1225" height="1000" data="'file here'"></object>
接受-file.php
if(!$_FILES['file']['error'])
{
$new_file_name = strtolower($_FILES['file']['tmp_name']);
$allowedExts = array("php", "html");
$file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));
if($_FILES['file']['type'] !== 'text/html')
{
$valid_file = false;
$message = 'Oops! Your file\'s not supported.';
echo $message ;
}
else
{
$currentdir = getcwd();
$target = $currentdir .'/uploads/' . basename($_FILES['file']['name']);
$data = move_uploaded_file($_FILES['file']['tmp_name'], $target);
$contents = file_get_contents($target);
echo $contents;
}
}
答案 0 :(得分:2)
您可以在上传HTML文件后直接在<iframe>
中回显:
echo '<iframe src="' . $target . '"></iframe>';
$target
将成为HTML文件的路径。
答案 1 :(得分:0)
<iframe src="/upload/Uploaded_file.html" > </iframe>
如果您在数据库中存储完整路径而不是替换&#34; src&#34;内容与您的数据库值。