Jump to content

Upload files


torsuntsu

Recommended Posts

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

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/283341-upload-files/
Share on other sites

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);
Link to comment
https://forums.phpfreaks.com/topic/283341-upload-files/#findComment-1455714
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/283341-upload-files/#findComment-1455721
Share on other sites

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!)

Link to comment
https://forums.phpfreaks.com/topic/283341-upload-files/#findComment-1455724
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.