File upload php with file array

Go To


i try to upload files into my server also to my database.

However, i cannot upload them.

I can see my two files with below code,

echo $_FILES['file']['name'][0];
echo $_FILES['file']['name'][1];

$fileName = $_FILES['file']['name'][0];
$add = "" . $fileName;

if (move_uploaded_file($_FILES[file_up][tmp_name], $add)) {
    NCore::db('NEWS')->insertAsArray(array('CONTENT' => $_POST['TvSpotdesc'], 'ADD_DATE' => $date, 'TITLE' => $_POST['newsTitle'],IMAGE_MAIN => $add))->execute();
    echo "Haber başarıyla gönderildi.";
} else {
    echo "Failed to upload file Contact Site admin to fix the problem";
}else {
    echo $msg;

But above code does not upload my files, it goes directly to the else statement, why?

Failed to upload file Contact Site admin to fix the problem

2012-04-04 07:16
by Mert METİN


Your code should be outputting two notices and a warning from this line:

if (move_uploaded_file($_FILES[file_up][tmp_name], $add)) {

The two notices would be because you have not quoted file_up and tmp_name and the warning to inform you of the reason move_uploaded_file has failed, as documented. You should check out the logs to see these for yourself (development without seeing any error messages is not fun).

The reason it fails is that you cannot move a file to a remote server -- $add is not a local path.

2012-04-04 07:18
by Jon


Rename $_FILES[file_up][tmp_name] to $_FILES['file']['tmp_name']

There is no such variable as file_up as per the code you pasted. Also, files can only be stored on the same server. so gove relative path like /home/www/myapp/images/ instead of server name.

2012-04-04 07:22
by web-nomad