0

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.
0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

it says: UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded.. what does no file mean?
That means the file hasn't arrived. Maybe the file is too big, php usually have a default 2MB limit. Try adding ths at the beginning of your PHP script: ini_set('upload_max_filesize','32M');
hm still the same.. the image isn't bigger than 700kb anyway
found the mistake.. i had more than one "mynewimage" inputs in my html
1

Found it. There were more than one <input type="file" name="mynewimage"> in my html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.