0

I am playing with an uploader on PHP. Basically, I did a simple one just for echoing what is chosen from submit button for right now.

<? php
echo $name  = $_FILES['file]['name'];

?>

<form action="upload.php" method="POST" enctpe="multipart/form-data">

<input type ="file" name="file"> <br> <br>
<input type="submit" value ="Submit">

</form> 

I am using and where I located this file is in a folder in htdocs. apache is running, PHP is running without hesitating whenever I refresh

http://localhost:81/phpex/upload.php

It just doesn't work and not echoing choosen file name.

Can you tell me what, actually, is wrong with it?

10
  • Can you please post the contents of phpex/upload.php? And is this page in the phpex directory? Commented May 19, 2015 at 13:26
  • 1
    just above what you see in code brackets @BenPearlKahan Commented May 19, 2015 at 13:27
  • Firstly, you have syntax error $_FILES['file]['name'];. Secondly: remove action="upload.php" Commented May 19, 2015 at 13:27
  • @Kristiyan ok fixed it still not working...secondly without defining action how it is supposed to pass submission into php paragraph? Commented May 19, 2015 at 13:30
  • Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); Commented May 19, 2015 at 13:30

3 Answers 3

2

Misspelling in your HTML: enctpe must be enctype.

Also I told you for syntax error echo $name = $_FILES['file']['name'];

Edit: Already tested:

<?php
if(isset($_POST)){ // prevent notice.
echo $name  = $_FILES['file']['name'];
}
?>
<form method="POST" enctype="multipart/form-data">
<input type ="file" name="file"> <br> <br>
<input type="submit" value ="Submit">
</form>
Sign up to request clarification or add additional context in comments.

8 Comments

@gobo, I've just edited my answer. You've wrong opening <?php tag. Please just copy/paste my code.
yours throws error Notice: Undefined index: file in C:\xampp\htdocs\phpex\upload.php on line 2
Your code return it. Upload file and it will work. I've change it.
That is because there is no test to see if $_FILES is set before assigning the variable.
@JayBlanchard after I fixed syntax <?php //error_reporting(E_ALL); ini_set('display_errors', 1); echo $name = $_FILES['file']['name']; ?> <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type ="file" name="file"> <br> <br> <input type="submit" value ="Submit"> </form> it gives an error as( ! ) Notice: Undefined index: file in C:\xampp\htdocs\phpex\upload.php on line 3
|
0
echo $name  = $_FILES['file]['name'];

should be

echo $name  = $_FILES['file']['name'];

- you missed out a quotation mark.

2 Comments

What is the difference between the two lines?
['file'] vs ['file]
0

have to show array _files to see all properites : var_dump($_FILES) ;

your code is correct i think just change name of file

 <input name="photo" type="file" id="photo" />


 <?php $photo=$_FILES["photo"]["name"];
    echo $photo ;
 ?>

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.