• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

$_FILES not working after move to dedicated server

My site was hosted on a shared server.  I am in the midst of trying to switch to a dedicated server after performace issues.  However, code that had been working on the old server is no longer working on the new.  It is a linux box, which i don't know very much about, so i'm trying to learn.  Specifically, code that was working to upload files is no longer working.  Here is the code:

 <table width="77%" border="0" cellspacing="0" cellpadding="3" align="center">
  <form action="?page=2" method="post" enctype="multipart/form-data">
  <tr>
    <td colspan="2"><div align="center"><strong><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">Upload
        CSV File</font></strong></div></td>
  </tr>
  <tr>
    <td width="22%">File</td>
    <td width="78%"><input type="hidden" name="MAX_FILE_SIZE" value="20000">
   <input type="file" name="csvfile"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value=" Submit "></td>
  </tr>
  </form>
</table>

However, after submitting the form, the $_FILES array is empty.

I think maybe it has to do with permissions on the temp directory.  The temp directory is not set in php.ini, so it is my understanding that it is using the default temp directory for the server.  
0
consultgal
Asked:
consultgal
  • 6
  • 2
1 Solution
 
mnb93Commented:
"The temp directory is not set in php.ini" : Have you set it? Because that is more than likely the problem
0
 
mnb93Commented:
According to what i’ve read on the manual, it seems to be caused by having

file_uploads = off

in the php.ini, or (as it was in my case), having no free space available.
0
 
mnb93Commented:
Don’t forget to always have the form tag include the enctype=”multipart/form-data”
If you don’t put this in, you won’t see anything in your _FILES var.

Uhhhgh! I’m an idiot! Aside from needing to have enctype=multipart/form-data, I found that i had made my MAXFILESIZE hidden tag set too low, PHP parses this and will spit out 2 as the value for the error element in the files hash.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mnb93Commented:
http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/

check  
 
1) Whether file upload is enabled in your php.ini.
 
2) Check whether the temporary upload folder is set correctly in  
php.ini file.
 
3) The html tag form sometime must have the attribute
'enctype="multipart/form-data"' set.

http://www.faqts.com/knowledge_base/view.phtml/aid/19252

Hopefully these help.
0
 
consultgalAuthor Commented:
1. File upload ins enabled in php.ini

2. This is what I think the problem is.  Can someone please tell me the correct way to set this?  After leaving it empty, thinking that it would just use the default for the server which should have the appropriate permissions, I currently have it set to "./tmp/".  However, since I know nothing about linux, I don't know where that driectory actually resides so that I can check for the appropriate permissions.

3. As you can see in my code snippet above, I do have that.
0
 
mnb93Commented:
file_uploads = On
upload_max_filesize = 2M


"I currently have it set to \"./tmp/\"."  What is the config line that you set?

Try deleting it.


" <table width="77%" border="0" cellspacing="0" cellpadding="3" align="center">
  <form action="?page=2" method="post" enctype="multipart/form-data">
  <tr>
    <td colspan="2"><div align="center"><strong><font size="+2" face="Verdana, Arial, Helvetica, sans-serif">Upload
        CSV File</font></strong></div></td>
  </tr>
  <tr>
    <td width="22%">File</td>
    <td width="78%"><input type="hidden" name="MAX_FILE_SIZE" value="20000">
   <input type="file" name="csvfile"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value=" Submit "></td>
  </tr>
  </form>
</table>"

For "?page=2" can you test it with:

<?php

print_f($_GET);
print_f($_POST);
print_f($_FILES);

?>

The global $_FILES  exists as of PHP 4.1.0 (Use $HTTP_POST_FILES  instead if using an earlier version). These arrays will contain all the uploaded file information.

Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well.
0
 
mnb93Commented:
Thanks for the points, I would also like to know what fixed it?

Steven
0
 
consultgalAuthor Commented:
Oops, I thought I posted a response....weird.

Anyway, what I thought I said was: my dedicated server was running version 3.x of MySQL, which not only explains the above problem but another one I was having with a query using UNION.  Doh!  Now, being a Linux newbie I just need to figure out how to install a GPG key so I can upgrade.

Thanks!

Courtney
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now