Reputation: 1288
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 = "img01.imgsinemalar.com/images/haber_anasayfa/" . $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
Upvotes: 0
Views: 594
Reputation: 6013
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.
Upvotes: 0
Reputation: 437804
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.
Upvotes: 1