0

I have a problem with uploading file with PHP. The html code is

<form enctype="multipart/form-data" id="form" action="action.php">
    <input type="file" name="file"/><br/><br/>
    <input type="submit" id="upload" value="Upload"/>
</form> 

and the PHP segment is

if($_FILES["file"]["error"]>0){
    $result['status'] = -1;
    $result['message'] = 'Unknown Error';
}
else{
    $file = $_FILES["file"];
    $savepath = '/CSV Files/'.$file["name"];
    move_uploaded_file($file['tmp_name'],$savepath);
}

The problem is the $result['status'] is not -1, but the $file is a null. And the strange thing is, the code worked well days ago, and suddenly died recently.Hope somebody could help me out. Thanks a lot!

8
  • show us print_r($_FILES); Commented Feb 19, 2014 at 19:20
  • print_r($file); what does it print? Commented Feb 19, 2014 at 19:20
  • How does code suddenly stop working? Climate change? Commented Feb 19, 2014 at 19:25
  • print_r($_FILES) says true. Commented Feb 19, 2014 at 19:27
  • Sidenote: You're using an absolute path $savepath = '/CSV Files/'.$file["name"]; which may not work. If running your code from the root, change it to $savepath = 'CSV Files/'.$file["name"]; without the leading / while making sure the folder has write permissions set. You should also consider not using a space between CSV and Files but using an underscore. @CharlesDou Commented Feb 19, 2014 at 19:27

1 Answer 1

1

You have missed to add method="POST" in your <form> tag

<form method="POST" enctype="multipart/form-data" id="form" action="design.php">
      ^^^^^^^^^^^^^
Sign up to request clarification or add additional context in comments.

4 Comments

May be the reason for upload folder path
Well, I didn't provide the full path in here, but I am sure the path itself has no problem. The problem is $_FILES is empty.
print_r($_FILES); what is the output
var_dump($_FILES) says "array(0) {}" and print_r($_FILES) says "Array()"

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.