torsuntsu Posted October 27, 2013 Share Posted October 27, 2013 I´m trying to implement a file upload functionality in my site, but for some reason i´m not being able to do it. I don´t receive any errors, in fact o get a success message. But when i check the folder the file isn´t there, as if it hasn´t been uploaded. The code i´m using is really straight forward: <?php $name = $_FILES['meuFicheiro']['name']; $type = $_FILES['meuFicheiro']['type']; $size = $_FILES['meuFicheiro']['size']; $temp = $_FILES['meuFicheiro']['temp_name']; $error = $_FILES['meuFicheiro']['error']; if ($error > 0){ die("Erro no upload do ficheiro"); } else { move_uploaded_file($temp,"uploads/".$name); echo "Ficheiro transferido com sucesso!"; } ?> Some help would be very appreciated. Thanks, TorSunTSU Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 27, 2013 Share Posted October 27, 2013 Have you tried printing out the variables? A quick test tells me that an error of the info not being set will pass your error test. In the following code there is no $_FILES* variable defined, so prints "there"... $error = $_FILES['meuFicheiro']['error']; if($error>0){echo "here";}else{echo "there";}To see errors whilst debugging add the following to the top of the page... error_reporting(E_ALL); ini_set('display_errors',E_ALL); Quote Link to comment Share on other sites More sharing options...
torsuntsu Posted October 27, 2013 Author Share Posted October 27, 2013 Tanks Mentalist, but as i said i get no errors. I´ve echoed the content of the variables and everything is fine. I can´t figure it out. Thanks any way... Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 27, 2013 Share Posted October 27, 2013 OK, so has move_uploaded_file() got write permissions for the target directory? (i.e. can you simply write a new file to that directory?) Quote Link to comment Share on other sites More sharing options...
torsuntsu Posted October 27, 2013 Author Share Posted October 27, 2013 I´ve checked the folder permissions and everything seems to be fine. I´m using filezila and i transfered a file to the folder without problems. I´m really stuck with this one. It seemed like such an easy thing to do.... Thanks for the replies Mentalist. Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 27, 2013 Share Posted October 27, 2013 Filezilla may log in as diff/right user, PHP/Server may be diff user with diff group permissions, etc! Also in various other examples i've just looked at they use an absolute dest address (filesystem, not sever)...??? Quote Link to comment Share on other sites More sharing options...
torsuntsu Posted October 27, 2013 Author Share Posted October 27, 2013 I´m really new to this things Mentalist. There is one variable that isn´t echoed. The variable $temp. When i echo that variable nothing shows. Could that be the problem. But if the variable is empty how come does the function move_uploaded_file($temp,"uploads/".$name); work? I don´t get it... Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 27, 2013 Share Posted October 27, 2013 (edited) I´m really new to this things Mentalist. There is one variable that isn´t echoed. The variable $temp. When i echo that variable nothing shows. Could that be the problem. But if the variable is empty how come does the function move_uploaded_file($temp,"uploads/".$name); work? I don´t get it... lol, change "temp_name" to "tmp_name" ... EDIT: You don't know if move_uploaded_file() worked because you don't check the return code in the shown code! (returns true on success!) Edited October 27, 2013 by mentalist Quote Link to comment Share on other sites More sharing options...
Solution torsuntsu Posted October 27, 2013 Author Solution Share Posted October 27, 2013 LOL, that was the problem... Thanks Mentalist... You guys are great... Many thanks Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 27, 2013 Share Posted October 27, 2013 Those are 99% of all errors, even after over 30 years of doing it, we're only human Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.