0

Im getting an image from my app to this php code:

<?php 

$target = "upload/"; 
$name="checks";
$target = $target . basename( $_FILES['uploaded'].$name); 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "yes";
} 
else {
echo "no";
}
?> 

The problem is that every name of a picture that I upload starts with "Array".

for example, $name is now "checks", so the filename would be "Arraychecks".

Why is this happening?

Thank you for your assistance.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
mn6vdv23g
  • 734
  • 2
  • 10
  • 33
  • Please stop adding further questions into the original one as soon as you get the previous ones answered. Stack Overflow aims to be a knowledge base in Q&A format, not a free consulting service. You should use the [Ask Question](http://stackoverflow.com/questions/ask) button or, even better, search first among the existing answers. – Álvaro González Aug 29 '13 at 10:19

3 Answers3

1

$_FILES['uploaded'] is an array.

Array
(
    [name] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [type] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [tmp_name] => Array
        (
            [1] => Array
                (
                    [0] => 
                )

        )

    [error] => Array
        (
            [1] => Array
                (
                    [0] => 4
                )

        )

    [size] => Array
        (
            [1] => Array
                (
                    [0] => 0
                )

        )

)

You're probably looking for $_FILES['uploaded']['name']

Ben Fortune
  • 31,623
  • 10
  • 79
  • 80
  • Im sorry, you are right. My real question is how can I change the name of the file Im getting before saving it, so there wont be collusions? – mn6vdv23g Aug 29 '13 at 09:32
1
$name = $_FILES['checks']['name'];
$fileElementName = 'checks';
$path = 'upload/'; 
$location = $path . $_FILES['checks']['name']; 
move_uploaded_file($_FILES['checks']['tmp_name'], $location); 

now in your insert query use $name

chirag ode
  • 950
  • 7
  • 15
1

Getting the word Array is a typical symptom of casting an array to string:

$data = array(10, 20, 30);
var_dump( (string)$data );
// Notice: Array to string conversion
// string(5) "Array"

It's obvious from your code that $_FILES['uploaded'] is an array because you do this:

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 

... so this can't be right:

$target = $target . basename( $_FILES['uploaded'].$name); 

Perhaps you had this in mind:

$target = $target . basename( $_FILES['uploaded']['name'].$name); 
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • yes. that is what I had in my mind. Ty! but can you also tell me how can I add the extantion to the filename? because right now the image saves it without it. – mn6vdv23g Aug 29 '13 at 09:41
  • [How to extract a file extension in PHP](http://stackoverflow.com/questions/173868/how-to-extract-a-file-extension-in-php) – Álvaro González Aug 29 '13 at 09:45