我在XAMPP上使用ubuntu os。在这里,我创建了两个文件uploader.php和phpEx6.php 当我尝试上传文件时,它显示警告信息。我是php.pls的新手帮助解决问题..
phpEx6.php
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="uploader.php" method="post" enctype="multipart/form- data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
uploader.php
<?php
if( $_FILES['file']['name'] != "" )
{
error_reporting(E_ALL);
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/opt/lampp/htdocs/xampp/nf/uploads/' $_FILES['file']['name'])
or die("Couldn't copy the file.");
}
else
{
die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>enter code here
<h2>Uploaded File Info:</h2>
<ul>
<li>Sent file: <?php echo $_FILES['file']['name']; ?>
<li>File size: <?php echo $_FILES['file']['size']; ?> bytes
<li>File type: <?php echo $_FILES['file']['type']; ?>
</ul>
</body>
</html>
输出
警告:move_uploaded_file(/opt/lampp/htdocs/opt/lampp/htdocs/xampp/nf/uploads/sam.txt):无法打开流:/ opt / lampp / htdocs / xampp中没有此类文件或目录第5行的/nf/uploader.php
警告: move_uploaded_file():无法移动&#39; / opt / lampp / temp / php1BAGC1&#39; to&#39; /opt/lampp/htdocs/opt/lampp/htdocs/xampp/nf/uploads/sam.txt'在第5行的/opt/lampp/htdocs/xampp/nf/uploader.php
答案 0 :(得分:1)
尝试改变这个
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/opt/lampp/htdocs/xampp/nf/uploads/'. $_FILES['file']['name'])
用这个
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/xampp/nf/uploads/'. $_FILES['file']['name'])
甚至是
move_uploaded_file($_FILES['file']['tmp_name'], '/opt/lampp/htdocs/xampp/nf/uploads/'. $_FILES['file']['name'])
答案 1 :(得分:0)
错误是,没有创建文件夹,你试图移动文件..创建文件夹,然后尝试它或检查文件夹是否具有上传文件所需的所有权限.. 以下是上传文件的示例代码..
if(isset($_POST['Submit']))
{
$tmp_name = $_FILES['Pic']['tmp_name'];
$name = $_FILES['Pic']['name'];
if(is_uploaded_file($tmp_name))
{
$org_name = time()."_".$name;
$dest = "uploads/$org_name";
move_uploaded_file($tmp_name, $dest);
}
}
答案 2 :(得分:0)
您的问题可以有多个答案如下:
答案 3 :(得分:0)
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/xampp/nf/uploads/'. $_FILES['file']['name'])
@Peter Darmis