jeffsss
jeffsss

Reputation: 1

can't upload image using php

I'm having problems uploading an image to a server.

My form code is as below:

<form enctype="multipart/form-data" action="upload_image.php" method="POST">
<label for="file[]">Image 1: </label><input type="file" name="file[]" id="file[]" />
    <br / >
<label for="file[]">Image 2: </label><input type="file" name="file[]" id="file[]" />
<br / >
<input type="submit" value="Upload" /> </form>

My upload_image.php code is as below:

<?php
 move_uploaded_file( $_FILES["file"]["name"][0], "upload/" . $_FILES["file"]["name"][0]);
 move_uploaded_file( $_FILES["file"]["name"][1], "upload/" . $_FILES["file"]["name"][1]); ?>

When I try to upload images, nothing happens, and no image is uploaded to the server. Please help me find what went wrong with my script.

Thanks a lot in advance.

Upvotes: 0

Views: 1184

Answers (1)

Julian Hinderer
Julian Hinderer

Reputation: 169

I think you have to use 'tmp_name' in the first part.

<?php
move_uploaded_file( $_FILES["file"]["tmp_name"][0], "upload/" . $_FILES["file"]["name"][0]);
move_uploaded_file( $_FILES["file"]["tmp_name"][1], "upload/" . $_FILES["file"]["name"][1]); ?>

Upvotes: 1

Related Questions