Reputation: 131
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.
Upvotes: 0
Views: 4791
Reputation: 74220
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.
Upvotes: 1