连接HTML和PHP

ebe*_*eth 2 html php upload

我正在尝试将文件上传到名为directory的文件夹中.我有一个上传表单的HTML代码,一旦我选择了所需的文件,我按下上传,PHP代码显示在浏览器中,文件根本没有上传.

我是PHP的新手.我以前做过HTML和CSS.可能是一点点Javascript,但不是PHP.我将uploader.php放在一个单独的文件中,而不是HTML代码.他们都在下面:

myHTML.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<?php
include 'uploader.php';
?>

<p>  
<h1> Advanced Tablet Based Visualization of Volumetric Data </h1>
</p>

 <p>
 Available files:
 </p>
 HELLO WORLD!!
 <form action="">
 <input type="button" value="Open"> <input type="button" value="Delete">
 </form>

 <hr />

 <p>
 <!-- Upload file source code: http://www.tizag.com/phpT/fileupload.php -->

 <form enctype="multipart/form-data" action="uploader.php" method="POST">
 <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 <br /> <br />
 <hr />
 Last Updated: October 24, 2011

 <br />
 Sponsored by:
 University of Notre Dame <img src="ndLogo" alt="ND logo" width="32" height="32"s />        
 <br />
 </p>

 </html>
 </body>
Run Code Online (Sandbox Code Playgroud)

uploader.php:

// Where the file is going to be placed 
$target_path = "uploads/";

 /* Add the original filename to our target path.  
 Result is "uploads/filename.extension" */  
 $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

 $target_path = "uploads/";

 $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
     echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
     " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
Run Code Online (Sandbox Code Playgroud)

Fos*_*sco 6

upload.php文件需要以php开始标记开头.

<?php
Run Code Online (Sandbox Code Playgroud)

此.html文件也应该具有.php扩展名,因为大多数Web服务器使用文件扩展名来确定如何处理请求.