Upload Form + GoDaddy hosting issue?

Hi all,

I’m having a really hard time even figuring out what my problem is here. I’ve searched all over the web for code snippets that will perform a simple image upload, and I’m getting dead end after dead end. Here is what I know:

I’m relatively sure my code is good - if it’s not perfect, it at least fires. I know this, because I get echo statements to output when I debug it at certain places. What’s odd though, is that if I try to just do any of the following:

echo $_FILES;
echo $_FILES[“file”];
echo $_FILES[“file”][“type”];

…I get blanks for all three.

I am using godaddy as my web host. I’ve read some things online about how people are having issues doing the same thing, but the fix is never clear. Does anyone think they might be able to help? I can also post code on request.

Thanks everyone

Post your code without a request.

Ha - sorry all. Rookie move. Here’s my code:

Here is the code where my form resides. It is a .php file. At the top, within the tag, I have:

<?php include 'upload_file.php' ?>

Below, in the body, is the form itself:

<form action="upload_file.php" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="Submit">
</form>

Then another file in the same directory: “upload_file.php”:

[php]

<?php $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); echo $_FILES . "
"; echo $_FILES['file'] . "
"; echo $_FILES["file"]["type"] . "
"; if ( ( ($_FILES["file"]["type"] == "image/gif") OR ($_FILES["file"]["type"] == "image/jpeg") OR ($_FILES["file"]["type"] == "image/jpg") OR ($_FILES["file"]["type"] == "image/pjpeg") OR ($_FILES["file"]["type"] == "image/x-png") OR ($_FILES["file"]["type"] == "image/png") ) AND ($_FILES["file"]["size"] < 20000) AND ( in_array($extension, $allowedExts) ) ) { echo "DEBUG 1
"; if ($_FILES["file"]["error"] > 0) { echo "DEBUG 2
"; echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "DEBUG 3
"; echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if (file_exists("uploadsTEST/" . $_FILES["file"]["name"])) { echo "DEBUG 4
"; echo $_FILES["file"]["name"] . " already exists. "; } else { echo "DEBUG 5
"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploadsTEST/" . $_FILES["file"]["name"]; } } } else { echo "DEBUG 6
"; echo "Invalid file"; } ?>

[/php]

It’s also worth noting that I have another directory within this one called “uploadsTEST” where I am attempting to have all uploaded images end up.

When I try uploading a 4kb jpeg file, I see my debug code echoed from the php file at the top of the page with the form. All echo’s at the top of the php file that have “$_FILE” are blank. Below that, I also see my debug code, which outputs “DEBUG 1” and then “DEBUG 6”, meaning it just thinks the file is invalid.

Thank you very much in advance. Sorry for the lengthy reply.
-Phil

In case you didnt know, that code is a cut and paste from w3schools except for the debug echos.

Increase the allowed file size. The code works.

I did know. That’s where I got it. This is one of the dozen examples of code I found all over the web, none of which have worked. I just figured this would be the most reliable one to use, and verify with other users on this site.

Also, as you’ll see, my debug code that uses echoes for the following:

echo $_FILES . “
”;
echo $_FILES[‘file’] . “
”;
echo $_FILES[“file”][“type”] . “
”;

are actually above the if statement that checks for file size. Yet, as I stated, these are blank when I attempt to upload a 4k image.

Are you certain this could be the case if the file size is the issue? If so, how do I increase the allowed file size aside from increasing the value in the if statement?

Thank you!

Are you certain this could be the case if the file size is the issue?

Yes, I am sure. Why not just try it instead of asking if I am sure?

how do I increase the allowed file size aside from increasing the value in the if statement?
The default upload size for PHP is 2 meg. If you want to upload bigger you need to edit your php.ini.

If you run the code they show as is and your paths and permissions are correct, the code works. It doesn’t need debug statements. It will even work on windows.

Try using just the first example they give. Keep it simple

[php]<?php
if ($_FILES[“file”][“error”] > 0)
{
echo "Error: " . $_FILES[“file”][“error”] . “
”;
}
else
{
echo "Upload: " . $_FILES[“file”][“name”] . “
”;
echo "Type: " . $_FILES[“file”][“type”] . “
”;
echo “Size: " . ($_FILES[“file”][“size”] / 1024) . " kB
”;
echo "Stored in: " . $_FILES[“file”][“tmp_name”];
}
?>[/php]

I have not created a php.ini file. Where might I find this? I have looked in many other directories within the server and haven’t been able to find it.

Also, the reason I asked that question is because, as I stated, the file I’m attempting to upload is 4 kb. If the default size limit is 2 meg, that should be no problem at all.

If you run the code they show as is and your paths and permissions are correct, the code works.

If you run the phpinfo function it will tell you exactly where php.ini is. You dont create it. It is part if PHP.

Sorry to be a pain.

But I also tried the first example they gave. Once I try to upload the 4k file, the page will refresh, and this is what I see at the top of my page (the one with the form):

Upload:
Type:
Size: 0 kB
Stored in:

So this makes me feel like you’re right by saying my paths or permissions are wrong. My problem is though, how would I know if it’s my permissions? What steps should I take to ensure they’re correct?

Thanks again.

Update. Note: This would be extremely helpful in the future for helping anyone else that comes across the same issue I have been having.

Although I have yet to figure out exactly how to upload the file and put it in the desired directory, I have figured out the root of the issue I was having, which was the fact that “$_FILES” was blank.

The actual issue has nothing to do with the php.ini file, default file size (mine was 24M while the file I was attempting to upload was 4K), or permissions.

After searching some more, I found a post on a forum that suggested to isolate the form on a .php or .html file BY ITSELF without any other forms. The .php file I was using to display this particular form (used to upload a file) also has several other forms on it, none of which are related to this. Once I took the form and put it on a page by itself, “$_FILES” was no longer empty. The fix revolves around the fact that if you have multiple forms on one page, you MUST have:

enctype=“multipart/form-data”

on ALL of the forms on that page, regardless of whether or not they are accomplishing this task.

Of course, I have yet to verify this, but right now, if the form is on its own page, I have at least avoided a blank “$_FILES” stopping me before I’ve even started.

Thank you for your help. I know it’s annoying helping a random stranger who seems to be having trivial issues, and it takes a great deal of patience. I appreciate it very much.

RESOLVED:

I just wanted to post again for reference that I put:

enctype=“multipart/form-data”

in every form on that page, and that fixed my issue.

Thanks again.

Sounds like your forms/page are not setup correctly. You should not have to add that to all the forms.

Sponsor our Newsletter | Privacy Policy | Terms of Service