PHP Uploads to "htdocs" and my "upload" dir
Posted: 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.
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 />';
?>