help.
all of a sudden, UPLOADING of files in all my forms didnt work.
i tried may things as i had googled it. i tested the code, $_FILES seemed to be empty.

free-up /tmp folder
check php.ini; increase post_max_size, upload_max_filesize, memory_limit
restart apache after each configuration
folders are not read only.
users have read/write permissions.
forms already have enctype="multipart/form-data"

when i tried var_dump($_FILES);
array(0) { } appears.

i dont know else what to do.please help me.we need to upload files everyday.
i didnt change anything in my code.
please please please

thank you.

It's better if you include a sample of the HTML you use to submit files, along with the .php file which receives that submission.

Especially considering you're confident about file permissions.

here:

<?php

$fName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$japSize = $_FILES['userfile']['size'];
$uploadDir ="/srv/www/htdocs/dirupload";                            
$filePath = $uploadDir . $fName;

if ($upload == 'Upload')
{

    if ($fName == '' )  
    {
        echo "<script>alert('Please complete the information!')</script>";    
    }else{
        $result = move_uploaded_file($tmpName, $filePath);

        if (!$result) 
        {
            echo "<script>alert('Error Uploading File!')</script>";
            exit;
        }else{
            echo "<script>alert('Uploading of file successful')</script>";
        }
    }
}
?>

$uploadDir . $fName will result in "/srv/www/htdocs/diruploadfileName
You're missing a forward slash.
Otherwise, you already stated that $_FILES is empty, therefor the entire script will fail.
You should include the <form> you use to submit the file [plain HTML]

here:

<form  method="post" enctype="multipart/form-data">

      Press browse to select what file to upload:

      <input name='userfile' type='file' id='userfile' size="45">

    <input name='upload' type='submit' class='box' id='upload' value='Upload'>

</form>

i did not changed anything in my code. like, yesterday it was ok.
then today, suddenly, it cannot upload.

i tried to echo the value of $fname, and its null/empty,
that's why it kept on alerting "Please complete the information"
even i browse the file i need to upload.

i think its about the configuration??
please help...thank you.

You have no form action.

You have no form action.
<form action=

I support @Unimportants answer. If your form is on the same file as the processing script above you'll need: action="<?php $_SERVER['PHP_SELF']; ?>"

Member Avatar for diafol

You can actually leave out the action attribute altogether and it should default to the current page. However, this can be a vulnerability in some implementations in some languages (asp.net and jsp), where one can use an iframe to attach a querystring to prioritise a request (GET vs POST). For PHP, always use a $_POST or $_GET, never $_REQUEST if this can be avoided. Nothing can be trusted of course and so everything must be sanitized and validated. Some suggest using 'action=""'. This apparently is not valid html5.

Sorry, off topic there.

Your code:

I can't see any reference to $upload - where does this come from?
If you check for isset($_FILES['userfile']) and then for $_FILES['userfile']['error'] == 0. If the last comparison is true, then you should have all your other $_FILES['userfile'] items.

arrghh..

i already inserted: action="<?php $_SERVER['PHP_SELF']; ?>"

still not working.
@diafol, $upload is:

$upload = $_POST['upload'];

i tried

if ($_FILES['userfile']['error'] == 0) {
    echo "No error";
}

it displays, "No error".
But something was displayed: Notice: Undefined index: userfile

what does did mean??

please help..thanks../

Is the file which contains the form the same file as the script which processes uploads?

It means that the index userfile has no value.

As Unimportant states are the following snippets in the same file?:

    <?php
    $fName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $japSize = $_FILES['userfile']['size'];
    $uploadDir ="/srv/www/htdocs/dirupload";
    $filePath = $uploadDir . $fName;
    if ($upload == 'Upload')
    {
    if ($fName == '' )
    {
    echo "<script>alert('Please complete the information!')</script>";
    }else{
    $result = move_uploaded_file($tmpName, $filePath);
    if (!$result)
    {
    echo "<script>alert('Error Uploading File!')</script>";
    exit;
    }else{
    echo "<script>alert('Uploading of file successful')</script>";
    }
    }
    }
    ?>

and this:

    <form method="post" enctype="multipart/form-data">
    Press browse to select what file to upload:
    <input name='userfile' type='file' id='userfile' size="45">
    <input name='upload' type='submit' class='box' id='upload' value='Upload'>
    </form>

Also, though off-topic, isn't it safer/more reliable to use:

if(isset($_POST['userfile'])){

in comparison to:

if ($upload == 'Upload'){

yes.they are in the same file.
do i need to separate them?

but all other projects have the same construction like this one.
which are all working before.

@mmcdonald.. i tried if(isset($_POST['userfile'])){ butit returns FALSE.

please help...
the users are bugging me out..they cannot upload.... :'(

When i looked at your php upload script, i noticed that one of the
lines in your code is incorrect.
You notice that if your file name is deozio.txt,
then line $filePath = $uploadDir . $fName; in your code will result in
"/srv/www/htdocs/diruploaddeozio.txt" and since your file is called
deozio.txt and not diruploaddeozio.txt, your script will not be able to upload
the file since you are feeding it with the wrong file name
Please correct the line of code below
$filePath = $uploadDir . $fName;
to
$filePath = $uploadDir."/". $fName;
and you should be good to go.

I hope that sorts your problem.

Member Avatar for diafol
<?php
    if(isset($_FILES['userfile']))
    {
       if($_FILES['userfile']['error'] == 0)
       {
            echo "uploaded";
       }else{
           echo "couldn't upload";
       }
    }
?>

<!DOCTYPE HTML>
<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
Press browse to select what file to upload:
<input name='userfile' type='file' id='userfile' size="45">
<input name='upload' type='submit' class='box' id='upload' value='Upload'>
</form>
</body>
</html>

Try that - see what happens on submit.

hey everyone..
as i have said before. i didnt change anything in the code.
all was working before.
its just server side issue.

thanks to all your replies.. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.