Reputation: 25
I am using ubuntu os with XAMPP. Here i've created two files uploader.php and phpEx6.php when i try to upload a file it shows warning message.I am new to php.pls help to solve the problem..
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>
OUTPUT
Warning: move_uploaded_file(/opt/lampp/htdocs/opt/lampp/htdocs/xampp/nf/uploads/sam.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/xampp/nf/uploader.php on line 5
Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/php1BAGC1' to '/opt/lampp/htdocs/opt/lampp/htdocs/xampp/nf/uploads/sam.txt' in /opt/lampp/htdocs/xampp/nf/uploader.php on line 5
Upvotes: 1
Views: 2422
Reputation: 25
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/xampp/nf/uploads/'. $_FILES['file']['name'])
@Peter Darmis
Upvotes: 0
Reputation:
try altering this
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/opt/lampp/htdocs/xampp/nf/uploads/'. $_FILES['file']['name'])
with this
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/xampp/nf/uploads/'. $_FILES['file']['name'])
or even this
move_uploaded_file($_FILES['file']['tmp_name'], '/opt/lampp/htdocs/xampp/nf/uploads/'. $_FILES['file']['name'])
Upvotes: 1
Reputation: 495
there can be multiple answer for your questions as followed:
Upvotes: 0
Reputation: 310
The error is about, there's no folder created to which you are trying to move the files.. Create the folder and then try it or check whether the folder has all the permissions needed to upload the file into it.. Here's the sample code for Uploading a file..
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);
}
}
Upvotes: 0