samedi 27 juin 2015

PHP + Windows 7 + AMPPS: [function.copy]: failed to open stream: No such file or directory

I am new to PHP and AMPPS. I am trying a very simple file upload screen using this example:

http://ift.tt/VrDUcc

  1. The HTML asks user to upload a file.
  2. Then the Action Calls and "uploader.php".
  3. This uploader.php is supposed to move a file from source to target.
  4. file_uploads = On // In PHP INI file
  5. upload_tmp_dir = "C:\Users\t_dutta\Documents\Projects\AMPPS\Domains\test-domain2\tempfiles"
  6. The time stamp of temp directory above does get updated every time I run the HTML form.
  7. 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