I am new to PHP and AMPPS. I am trying a very simple file upload screen using this example:
- The HTML asks user to upload a file.
- Then the Action Calls and "uploader.php".
- This uploader.php is supposed to move a file from source to target.
- file_uploads = On // In PHP INI file
- upload_tmp_dir = "C:\Users\t_dutta\Documents\Projects\AMPPS\Domains\test-domain2\tempfiles"
- The time stamp of temp directory above does get updated every time I run the HTML form.
- In the code, I have pasted various versions of copy function I tried.
HTML Form (form.html) code:
<form action="php/uploader.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
PHP Code (uploader.php):
<?php
$file_path = "\\temp";
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$path = $root . "\\finalfiles\\";
$real_path = realpath($path);
if( $_FILES['file']['name'] != "" )
{
echo $_FILES['file']['name'] . "<p></p>";
echo $_SERVER['DOCUMENT_ROOT'] . "<p></p>";
echo $real_path . "<p></p>";
//Copy Function 1st Version
copy ($_FILES['file']['name'], $_SERVER["DOCUMENT_ROOT"]) or
die("<p>Could not copy file!</p>");
//Copy Function 2nd Version
//copy ($_FILES['file']['name'], $root) or
// die("<p>Could not copy file!</p>");
//Copy Function 3rd Version
//copy ($_FILES['file']['name'], $path) or
// die("<p>Could not copy file!</p>");
//Copy Function 4th Version
//copy ($_FILES['file']['name'],"C:\Users\t_dutta\Documents\Projects\AMPPS\
//Domains\test-domain2\finalfiles") or die("<p>Could not copy file!</p>");
}
else
{
die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>
<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>
Error Message:
PN.txt
C:/Users/t_dutta/Documents/Projects/AMPPS/Domains/test-domain2
C:\Users\t_dutta\Documents\Projects\AMPPS\Domains\test-domain2\finalfiles
Warning: copy(PN.txt) [function.copy]: failed to open stream: No such file or directory in C:\Users\t_dutta\Documents\Projects\AMPPS\Domains\test-domain2\php\uploader.php on line 13
Could not copy file!
Aucun commentaire:
Enregistrer un commentaire