0

I'm very new to php but worked a lot with javascript and html before. I'm hosting a server with apache on my own computer just for testing php. I installed php as cgi on it and everything worked fine. I did some testing with php just to get a feel for how it works, but when I tried to make a file upload form and read the file with php:

//uploadFile.php
<html>
    <head>
    </head>
    <body>
        <form action="uploadFile.php" id="form" method="POST" enctype="multipart/form-data">
            <input type="file" name="uploadFile">
            <input name="submit" value="upload" type="submit">
        </form>

        <?php
            echo $_FILES["uploadFile"]["name"];
        ?>
    </body>

</html>

I suddenly got the message:

No input file specified

Only that! It didn't even said it was an error. I tried this very simple php script that worked before:

<?php
echo "Working";
?>

But I still got "No input file specified". Every php file I try gives me this error, wich indcates that the problem is't in my code. When I tried a normal .html file without php it worked. I have tried researching it and it seams like peaple hosting on godaddy gets this message, but I found no solution for me.

Do anyone know the solution or have any tips on how to go about solving this problem.

Istlemin
  • 131
  • 2
  • 11

1 Answers1

1

As per your originally posted code/question where you changed your question after this answer has been submitted:

PHP is case sensitive when it comes to POST/FILES variables, or any variables for that matter.

You have name="uploadfile" and then $_FILES["uploadFile"]

Change it to $_FILES["uploadfile"]

F is not the same as f.

Or keep $_FILES["uploadFile"] and change name="uploadfile" to name="uploadFile".

Either way, they both much match in letter-case.


Read the manual on uploading files:


Edit: (example)

Sidenote:

Make sure the folder exists and has proper write permissions. You may need to adjust the way the $uploads_dir = 'uploads'; is, depending on where you are executing the code from.

<html>
    <head>
    </head>
    <body>
        <form action="" id="form" method="POST" enctype="multipart/form-data">
            <input type="file" name="uploadFile">
            <input name="submit" value="upload" type="submit">
        </form>

<?php
if(isset($_POST['submit'])){

$uploads_dir = 'uploads';
foreach ($_FILES["uploadFile"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["uploadFile"]["tmp_name"][$key];
        $name = $_FILES["uploadFile"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
  }

}

?>
    </body>

</html>

"When I tried a normal .html file without php it worked."

Make sure that the code in my answer is used as a .php file and not .html.

You should also contact GoDaddy's technical support regarding this matter, and to see if PHP is indeed available for you to use.


Add error reporting to the top of your file(s) which will help find errors.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Sidenote: Error reporting should only be done in staging, and never production.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • But I still get the same message for every php file – Istlemin Oct 16 '14 at 16:07
  • Since you're using all the code inside the same file, use `isset()` around `echo $_FILES["uploadFile"]["name"];` as in `if(isset($_POST['submit'])){ echo $_FILES["uploadFile"]["name"]; }` @Istlemin – Funk Forty Niner Oct 16 '14 at 16:09
  • @Istlemin Reload my answer, I've made an example edit. Make sure the folder exists and has proper write permissions. You may need to adjust the way the `$uploads_dir = 'uploads';` is, depending on where you are executing the code from. – Funk Forty Niner Oct 16 '14 at 16:13
  • @Istlemin Also make sure that the code in my answer is used as a `.php` file and not `.html` – Funk Forty Niner Oct 16 '14 at 16:18
  • As I just added to my question, every php file gives me this error, no matter what I put in in! It feels like you think the problem is in my file upload code. Sorry if my question was unclear – Istlemin Oct 16 '14 at 16:22
  • @Istlemin Which "error" exactly, "no input file specified"? I would contact GoDaddy/Tech support about this then. That doesn't make sense. I think it's a configuration issue somewhere, most likely `.htaccess` - have a look inside your error logs, there could be something in there. – Funk Forty Niner Oct 16 '14 at 16:24
  • @Istlemin I found a Q&A here on Stack that could help http://stackoverflow.com/q/14555996/ - Go over that entire page. Also http://stackoverflow.com/a/7028471/ – Funk Forty Niner Oct 16 '14 at 16:31
  • I think I clearly said I hosted it on my computer, not on goDaddy. And wich error logs? Apaches? I found no error there. And Where is the ..htaccess file? – Istlemin Oct 16 '14 at 16:48
  • @Istlemin Sorry about that, I thought you were hosted with that, apologies. Well, that's a different story. Firstly, is PHP indeed installed and properly configured? – Funk Forty Niner Oct 16 '14 at 16:50
  • @Istlemin Also make sure that the setting for uploading is enabled. I installed Wampserver last night on one of my machines and did notice a setting for it to that effect. As for log files, that will depend on the installation. – Funk Forty Niner Oct 16 '14 at 16:58