PHP Uploads to "htdocs" and my "upload" dir

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP Uploads to "htdocs" and my "upload" dir

Postby Reloaded » 22. April 2010 01:05

So i made a little upload script in PHP (still learning PHP) and i tell it to upload to "uploads" folder which is in the root document (C:/PHP Practice/xampp/uploads)

Well when i upload a file it uploads to the "upload" folder as it should, but it also places the file in "htdocs". Please help.

Code: Select all
   <?php
      if ($_FILES['userFile']['error'] > 0) {
         echo 'Problem: ';
         switch ($_FILES['userFile']['error']) {
            case 1:   echo 'File exceeded upload_max_filesize';
                        break;
            case 2:   echo 'File exceeded max_file_size';
                        break;
            case 3:   echo 'File only partially uploaded';
                        break;
            case 4:   echo 'No file uploaded';
                        break;
            case 6:   echo 'Cannot upload file: No temp directory specified';
                        break;
            case 7:   echo 'Upload failed: Cannot write to disk';
                        break;
         }
         exit;
      }
      
      // Does the file have the right MIME type?
      if ($_FILES['userFile']['type'] != 'text/plain') {
         echo 'Problem: File is not plain text';
         exit;
      }
      
      // Put the file where we'd like it
      $upFile = '../uploads/' .$_FILES['userFile']['name'];
      
      if (is_uploaded_file($_FILES['userFile']['tmp_name'])) {
         if (!move_uploaded_file($_FILES['userFile']['tmp_name'], $upFile)) {
            echo 'Problem: Could not move file to destination directory';
            exit;
         }
      }
      else {
         echo 'Problem: Possible file upload attack. Filename: ';
         echo $_FILES['userFile']['name'];
         exit;
      }
      
      echo 'File uploaded successfully!<br /><br />';
      
      // Remove possible HTML & PHP tags from the file's contents
      $contents = file_get_contents($upFile);
      $contents = strip_tags($contents);
      file_put_contents($_FILES['userFile']['name'], $contents);
      
      move_uploaded_file($_
      
      // Show what was uploaded
      echo '<p>Preview of uploaded file contents:<br /><hr />';
      echo nl2br($contents);
      echo '<br /><hr />';
   ?>
Reloaded
 
Posts: 1
Joined: 22. April 2010 00:56

Re: PHP Uploads to "htdocs" and my "upload" dir

Postby MC10 » 26. April 2010 02:43

There's some incomplete code:

Code: Select all
move_uploaded_file($_


If this is part of the original code, that might be the problem, but I think it is just a copy-and-paste mistake.
MC10
 
Posts: 148
Joined: 20. February 2010 20:13


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 45 guests