Naveed
Naveed

Reputation: 42093

PHP: Upload images from client machine to the server

I want to upload user images from client machine to server in php. The name of the image should be predefined.

Can any one tell me the php code for this?

Upvotes: 0

Views: 977

Answers (1)

Gordon
Gordon

Reputation: 316939

Will the example from the manual page for move_uploaded_file() do?

$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}

Also see the chapter on Handling File Uploads in the PHP Manual

Upvotes: 3

Related Questions