Insert upload values into an array with another name?

Asked

Viewed 46 times

0

My problem is this, I have a form where the user uploads, with that all right, but I would like it to enter with another name but if so, it inserts blank in the database.

$files=$rand."_".$_FILES['upload']['name'];
$array=implode(",", $files);
echo "<script>alert('Array: ".$array."')</script>";

With the code above, he sends the field $array empty but if I do $files=$_FILES['upload']['name']; he rules right.

1 answer

0


Dear friend, if I understand your intention I recommend you to use directly the prefixed indexes of the variable $_FILES of PHP.

Not returning values because you are using the implode bounded by "," but the $_FILES returns an array of positions as follows:

[file] => Array
    (
        [name] => MyFile.jpg
        [type] => image/jpeg
        [tmp_name] => /tmp/php/php6hst32
        [error] => UPLOAD_ERR_OK
        [size] => 13
    );

That’s why it doesn’t return value according to its code, why you didn’t inform an array index to work with and don’t have "," to delimit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.