Reputation: 2316
I want to upload an image to the folder /images
and keep its name
This is what i got:
html
<form action="script.php" method="post" enctype="multipart/form-data">
<input type="file" name="mynewimage">
<input type="submit">
</form>
php
if (!empty($_FILES['mynewimage']['name'])) {
move_uploaded_file($_FILES['mynewimage']['tmp_name'], "images/" . $_FILES["mynewimage"]["name"]);
}
/images folder is 777
error says: UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.
Upvotes: 0
Views: 828
Reputation: 2316
Found it. There were more than one <input type="file" name="mynewimage">
in my html
Upvotes: 1
Reputation: 3362
You should check for uploading errors:
if (isset($_FILES['mynewimage']) && $_FILES['mynewimage']['error']==0) {
....
}else{
die('Error uploading, code '.$_FILES['mynewimage']['error']);
}
Check error codes here.
Upvotes: 1