Help with basic Upload file script

I am testing out this upload script (from www.dropzonejs.com), and I thought I have done the basic install, as they instruct, and the chosen file (to upload) appears to upload successfully, but never appears in the file directory(file permission set to 777). Am I missing something? I’ve tried different paths, I’m stumped.

Here is the code, any suggestions/guidance will be appreciated:


<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="/dropzone/dist/dropzone.css">
<script src="/dropzone/dist/dropzone.js"></script>
</head>
<body>
<form action="/uploadTest.php" method="post" enctype="multipart/form-data" class="dropzone"
id="my-awesome-dropzone">
<input type="file" name="file" />
</form>
</body>
</html>
<?php

$uploaddir = '/new-uploads';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

I would have thought you need a slash at the end of your upload directory name?

$uploaddir = '/new-uploads';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

ie

$uploaddir = '/new-uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

Thanks for that suggestions. here’s the new code, however no success:

<?php

$uploaddir = '/new-uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

Any additional help will be welcomed.

Not seeing a submit button on your form. Uploading a file will only work if you post the form.

Add error_reporting(E_ALL); to the top of your php file. This might enable you to see any error or warning messages.

The fact that your file input element name is ‘file’ but your are trying to access $_FILES[‘userfile’] is not helping.

If you still have trouble then update your question with whatever print_r($_FILES) shows.

As ahundiak may have pointed out, the form is using the name “file” and your processing code is looking for “userfile”. Pick one or the other…

Thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.