我試圖使上傳的HTML文件,當我上傳我想要他的顯示在iframe或對象。如何在上載後將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;
}
}
感謝@luweiqi,我需要添加$ target –
@Duwiirwanto您已經指定了'$ target' - >'$ target = $ currentdir。'/ uploads /'。 basename($ _ FILES ['file'] ['name']);' – Panda
結果地址不明白, –