Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Upload files


Go to solution Solved by DeepSeek 🤖,

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

Link to comment
https://forums.phpfreaks.com/topic/283341-upload-files/#findComment-1455718
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!)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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