Rijstkoek
Rijstkoek

Reputation: 241

directory upload php some dirs work, some don't

I have 2 questions, first one:

I'm trying to upload all the files in a specific folder and move them to the user his private folder with PHP. My current code:

$count = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  foreach ($_FILES['files']['name'] as $i => $fname) {
    if (strlen($_FILES['files']['name'][$i]) > 1) {
      if (move_uploaded_file($_FILES['files']['tmp_name'][$i],
           'users/' . $currentUser . '/uploads/' . $fname)) {
        $count++;
      }
    }
  }
}

and

<div id="divUpload">
  <form method="post" enctype="multipart/form-data">
    <input type="file" name="files[]" id="files" 
      mozdirectory="" directory="" webkitdirectory="">
    <input class="button" type="submit" value="Upload" />
  </form>
</div>

The $count is used later to check if any files were uploaded.

This code works flawlessly on my localhost system but it doesn't seem to work on my ubuntu server on certain folders. For example: a folder with 20 images inside of it works just fine, while a folder with only 1 image can already give me an error.

I've updated my php.ini file and made these changes:

upload_max_filesize = 199M
max_file_uploads = 100

I will be the only one using this website and it's only possible to connect to it from my own network so don't worry about security. My www-data user also has full access to the folders on my server so I don't think it's a permission thing either.

When I try to debug my code using the php.ini-development it gives me the error

Warning: Invalid argument supplied for foreach() in /var/www/upload.php on line 14

and when I try to var_dump() it, it returns NULL as if no files were uploaded at all... Did I make a mistake somewhere? I'm pretty confused because it works sometimes without any problems...

Second question:

I read somewhere that the upload_max_filesize in php.ini is limited by the memory_limit. Is this true?

This project I'm making is a home NAS and I've managed to make my code run smoothly with a total memory_limit of 200M. Does this mean I won't be able to upload file which are larger then 200MB??? Why does this work on my localhost aswell then? (It uses the same 200M memory_limit constraint)

Thanks, S

Upvotes: 0

Views: 134

Answers (1)

Rijstkoek
Rijstkoek

Reputation: 241

Forgot to increase my

post_max_size

in php.ini aswell. This fixed the problem! Weird that PHP didn't give a clear message about this though.

S.

Upvotes: 2

Related Questions