8
On our hosting server, I have two projects, where both are with a module in our administrative area to manage images.
In the project To, the form is submitted to the server and the $_POST
is received by the server with the image field loaded.
In the proejcto B, the form is submitted to the server but the matrix of $_POST
arrives empty to the server, although in Firebug I can see that the field and the loaded image were sent.
Form
Same for project To and B
<form class="horizontal-form" enctype="multipart/form-data" method="post" action="#">
<div class="row-fluid">
<div class="span6">
<div class="control-group">
<label class="control-label">Carregar imagem</label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file">
<span class="fileupload-new">Selecionar ficheiro</span>
<span class="fileupload-exists">alterar</span>
<input type="file" class="default" name="img">
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">remover</a>
</div>
</div>
<span class="help-block">Escolha uma imagem para substituir a existente no site.</span>
</div>
</div>
</div>
<div class="span6">
<div class="control-group">
<label class="control-label">Pré-visualizar</label>
<div class="controls">
<div class="thumbnail item" style="width:244px">
<a href="http://www.meusite.com/caminho/para/imagem/imagem.jpg" title="Pré-visualização da imagem: imagem.jpg" class="fancybox-button">
<div class="zoom">
<img src="http://www.meusite.com/caminho/para/imagem/imagem.jpg" alt="" />
<div class="zoom-icon"></div>
</div>
</a>
<div class="details">
imagem.jpg
</div>
</div>
<span class="help-block">Pré-visualizar imagem existente</span>
</div>
</div>
</div>
</div>
<div class="form-actions text-right">
<button type="submit" class="btn blue"><i class="icon-ok"></i> Guardar alterações</button>
<a class="btn" href="?mod=website&call=images" title="">cancelar</a>
</div>
</form>
Information from the Firebug
Project To
Project B
I have already carried out a series of tests to understand what is going on, some of which may be relevant to finding the solution to this problem:
PHP file with nothing more than the form above.
In the project To and B the
var_dump($_POST);
Give me an empty matrix.Add extra field of type
hidden
or the typetext
to the project form B solves the problem and the matrix of$_POST
now arriving at the server in condition.Copy PHP file from project To for the project B to check any problems with the file itself (???), but the result is the same.
File check
.htaccess
to locate some directive to Apache, but both files are strictly the same and contains no instructions other than:# Use PHP5 AS DEFAULT AddHandler application/x-httpd-php5 .php # Frontpage # Set the files to be ignored when ussing the directory list IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* IndexIgnore * # BROWERS SERVER FILES VIEW DISABLE Options -Indexes # CUSTOM ERROR DOCUMENTS FOR APPACHE REDIRECT ErrorDocument 400 /error/400.htm ErrorDocument 401 /error/401.htm ErrorDocument 403 /error/403.htm ErrorDocument 404 /error/404.htm ErrorDocument 500 /error/500.htm
Test on different browsers and different computers to exclude browser or session problems.
The result was consistent in all tests, project To works well, project B doesn’t work.
Question
Why does the same form work in the project To, but flaw in the project B and tests with a simple form on both domains fail when you would expect that in the project To worked?
Doubt: the statement "In project A and B the var_dump($_POST); gives me an empty matrix." to contradict what you said in the second paragraph. That’s right?
– utluiz
Question #2: I noticed that in the images with the source, one has the attribute
name
worthwhilefilename
and another with valueimg
. That’s right?– utluiz
Have you tried comparing the
phpinfo()
of the two servers? It may be some different configuration.– bfavaretto
@utluiz Yes, within the administrative area where the forms are used, in the project To works, in the project B no. But if you take a file with only one form inside and put it in the root of each domain and try it, it doesn’t work in any of them. This is really weird...
– Zuul
@utluiz Yes, project To is named after
filename
and the project B is named afterimg
, although I have been "playing with" the names to see if it came from there (too short, too long...). This is to test some cause-effect relationship due to the name ofinput
.– Zuul
@bfavaretto As I said, both projects are on the same host server. The output of
phpinfo()
is strictly the same for all the people present in this machine, including the projects To and B :)– Zuul
According to this topic a possible cause would be to have a general URL rewriting to add "www" to the address of the requests that did not have it. Do you have something like this configured in Apache? I remember that when I configured Virtualhosts in Apache I mapped the two domain types (with and without "www") so I wouldn’t have any problems. Could that be it?
– utluiz
And maybe this other link give you some new idea. Also check if your host has specific "php.ini" configuration files by directory. I’ve already used this in some lodgings and can cause confusion.
– utluiz
Zuul, when you put an Hidden field the image arrives on the server too? Or will the value of Hidden but not the input file?
– Anthony Accioly
Some other ideas: Check if input file is not disabled, check if you are posting for correct action, check the variable
$_FILES
, and finally the settings of this post: http://stackoverflow.com/a/3587158/664577– Anthony Accioly
@Anthonyaccioly With any other input, the entire form arrives at the server and the image is loaded as expected! In short, with another field beyond the
file
, everything works fine.– Zuul
@Anthonyaccioly Ready, is already solved. This is really something that ready... : D Basically I was checking the
$_POST
when the form has nothing but$_FILES
:) Please add a response warning of this as was the case with your comment so that I can give the matter as resolved. And a big thank you, I was so involved in complex solutions that I didn’t even see the flaw in the verification. (Note: In the project To was checking out the$_FILES
, in the project B was checking out the$_POST
) And thank you all for your time!– Zuul