I've uploaded a file in PHP, it is in the array $_FILES, the tmp_name is filled with his name, but in fact the file has not been uploaded, why this happens? if the tmp_name is filled, does that mean that it should have been uploaded? because I even had set the folder to 0777, still can't upload, in the phpinfo(); - everything is on...help please
foreach($_FILES as $file)
{
foreach($file['tmp_name']['new'] as $name) {
echo '<br />'.$name.'<br />';
if(is_uploaded_file($name))
{
echo '1';
}
else
{
echo '0'; // shows this
}
//$res = move_uploaded_file($name, "/uploads");
//echo $res;
}
exit;
}
//exit;
the is_uploaded_file - returns false
Array
(
[name] => Array
(
[new] => Array
(
[prikrepit_fajl] =>
[prikrepit_fajl1] =>
[prikrepit_fajl3] => ava.png
[prikrepit_fajl333] => ava.png
[prikrepit_fajl55555555] =>
)
)
[type] => Array
(
[new] => Array
(
[prikrepit_fajl] =>
[prikrepit_fajl1] =>
[prikrepit_fajl3] => image/png
[prikrepit_fajl333] => image/png
[prikrepit_fajl55555555] =>
)
)
[tmp_name] => Array
(
[new] => Array
(
[prikrepit_fajl] =>
[prikrepit_fajl1] =>
[prikrepit_fajl3] => /home/users1/v/vizitka77/tmp/phppOtsIp
[prikrepit_fajl333] => /home/users1/v/vizitka77/tmp/phpgY6RQ9
[prikrepit_fajl55555555] =>
)
)
[error] => Array
(
[new] => Array
(
[prikrepit_fajl] => 4
[prikrepit_fajl1] => 4
[prikrepit_fajl3] => 0
[prikrepit_fajl333] => 0
[prikrepit_fajl55555555] => 4
)
)
[size] => Array
(
[new] => Array
(
[prikrepit_fajl] => 0
[prikrepit_fajl1] => 0
[prikrepit_fajl3] => 25352
[prikrepit_fajl333] => 25352
[prikrepit_fajl55555555] => 0
)
)
)
One important thing to point out: if you don't save the uploaded file during the request, PHP deletes it when the request terminates so the file will be gone.
Second, you are looping over the array incorrectly. You should try a for loop instead:
for ($i = 0; $i < sizeof($_FILES['new']['tmp_name']); ++$i) {
$name = $_FILES['new']['name'][$i];
$path = $_FILES['new']['tmp_name'][$i];
$err = $_FILES['new']['error'][$i];
if ($err != UPLOAD_ERR_OK) {
// check error code
// report error
continue;
}
if (is_uploaded_file($path)) {
// do something with the file
}
}
EDIT: In your commented code, move_uploaded_file($name, "/uploads");
is not the correct syntax for moving the file.
It should look more like:
move_uploaded_file($path, "uploads/{$name}");
Note: The above is dangerous if you haven't checked the file content and extension. Be very careful not to allow file uploads with a .php or other executable extension.
You should read this: http://php.net/manual/en/function.is-uploaded-file.php
And this: http://php.net/manual/en/features.file-upload.php
Looks like you are accessing $_FILES incorrectly.
foreach($_FILES['tmp_name']['new'] as $inputName => $file)
{
// $inputName is the name attribute from the HTML form
echo '<br />'.$file.'<br />';
if( is_uploaded_file($file) )
{
echo '1';
}
else
{
echo '0';
}
//$file = umiImageFile::upload('uploads',$name,'uploads','new');
//$res = move_uploaded_file($name, "/uploads");
//echo $res;
}