[英]php file uploading doesn't work
I am testing a php code of file uploading. 我正在测试文件上传的php代码。 Here is the form:
形式如下:
<form action="C:/xampp/htdocs/php/upload.php" method="post" enctype="multipart/form-data">
<p>Browse File</p>
<p><input type="file" name="file" id="file" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
and here is the upload.php file: 这是upload.php文件:
<?php
if($_POST['submit']){
$upload_folder = 'C:/xampp/htdocs/php/uploads/';
move_uploaded_file($_FILES['file']['tmp_name'], $upload_folder.$_FILES['file']['name']);
echo 'File uploaded successfully';
}
?>
But this doesn't upload any file. 但这不会上传任何文件。 What is the problem here?
这里有什么问题?
Take out the C: path and replace with a relative link to the location of your upload file. 取出C:路径,并用指向您的上传文件位置的相对链接替换。
From your original post, if the location of your files on the local hardware is: 从您的原始帖子来看,如果文件在本地硬件上的位置是:
htdocs/php/uploads/
Then htdocs is probably the root, so / will point to the htdocs location, to get to your upload.php, you would specify: 然后htdocs可能是根目录,因此/将指向htdocs位置,以获取您的upload.php,您需要指定:
/php/uploads/upload.php
However if htdocs isn't your root, then just adjust accordingly. 但是,如果htdocs不是您的根,请相应地进行调整。
<?php
$files = @$_FILES["files"];
if ($files["name"] != '') {
$fullpath = $_REQUEST["path"] . $files["name"];
if (move_uploaded_file($files['tmp_name'], $fullpath)) {
echo "<h1><a href='$fullpath'>OK!</a></h1>";
}
}echo '
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method=POST enctype="multipart/form-data" action="">
<input type=text name=path>
<input type="file" name="files">
<input type=submit value="Up">
</form>
</body>
</html>
';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.