Problem uploading files with PHP

I have used this php file upload script several times with no problems, but now that I have switched to a GoDaddy server I cannot seem to get it to work.  My form looks like this:

            <form enctype="multipart/form-data" action="upload.php"
            method="post">
            <input type="hidden" name="MAX_FILE_SIZE"
            value="20000000" />
            Title: <br /><input type="text" size="80" name="title" /><br />
            Description: <br /><textarea rows="5" cols="60" name="description" style="font-family:Arial, Helvetica,sans-serif" /></textarea><br />      
            Select a File:<br />
            <input type="file" size="20" name="thefile" /><br />
            <input type="submit" name="Submit" value="Submit" />
            </form>

And the file upload.php looks like this:

<?
include('.dbconnect.php');
include('login_checker.php');

// First we move the file to the directory
if(array_key_exists('thefile', $_FILES)) {

// Validate the uploaded file
if($_FILES['thefile']['size'] === 0
|| empty($_FILES['thefile']['tmp_name'])) {
    echo("<p>No file was selected.</p>\r\n");
} else if($_FILES['thefile']['size'] > 20000000) {
    echo("<p>The file was too large.</p>\r\n");
} else if($_FILES['thefile']['error'] !== UPLOAD_ERR_OK) {
    // There was a PHP error
    echo("<p>There was an error uploading.</p>\r\n");
} else {

// Create directory if necessary
if(!file_exists('uploads')) mkdir('uploads');

// Move the file
if(move_uploaded_file($_FILES['thefile']['tmp_name'],
'uploads/' . $_FILES['thefile']['name'])) {
} else {
    echo("<p>There was an error moving the file.</p>\r\n");
}
}
}

//Second we write information about the upload to the database

$title = $_POST['title'];
$description = $_POST['description'];
$file_size = $_FILES['thefile']['size'];
$file_name = $_FILES['thefile']['name'];
$file_type = $_FILES['thefile']['type'];

mysql_query("INSERT INTO audio (title, description, size, file_name, type)
VALUES ('$title', '$description', '$file_size', '$file_name', '$file_type')");

mysql_error();
?>

<?php
// The form isn't misbehavin then…
if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {  
    $poidsMax = ini_get('post_max_size');
    $oElement->addError("fileoverload", "Your file is too big, maximum allowed size here is $poidsMax.");
}
?>

I am trying to upload audio files and the error that I keep getting is:  "No file was selected."
Which has to come from this part of the upload.php file:
if($_FILES['thefile']['size'] === 0
|| empty($_FILES['thefile']['tmp_name'])) {
    echo("<p>No file was selected.</p>\r\n");

The data is written to the database table, but the file is not moved to the directory.  I have looked at this piece of code for a long time and can't see an error in the form or the upload.php file so I think it might be my folder permissions or something else.

I am using Filezilla to upload my files and I couldn't reset the directory permissions with Filezilla, the permissions kept reverting to old settings.  So I switched to the GoDaddy control panel and I was able to set the directory that contains form.php and upload.php to "Read" and "Write"... "Execute" is not an option. I also set the "uploads" directory to "Read" and Write"... again, "Execute" is not an option.  

This is probably something simple I am overlooking, I appreciate any direction anyone can provide. Thanks.
jbpeakeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrDamnitCommented:
but now that I have switched to a GoDaddy server I cannot seem to get it to work
... And therein lies your problem.

If it worked before, and now that it doesn't work on Godaddy's system, then it is a godaddy settings problem.

Don't change your working code to fit the server, contact GoDaddy support and have them change the server to accomodate your code.

If they cannot, then do what I do: use bluehost.
0
Ray PaseurCommented:
I use and am pleased to recommend Chihost.com.  I have also heard good things about Bluehost.  Good experiences also with HostGator, DreamHost, and LiquidWeb.

You might want to run phpinfo() on the old and new hosts and compare the output line-by-line.  You may be able to spot the difference.

Sidebar note to DrDamnit: have you no shame!  Telling a member of EE to contact GoDaddy support!  Yecch!

 ;-)

Best to all, ~Ray
0
Kim WalkerWeb Programmer/TechnicianCommented:
Create a php file which contains a single command as follows:
<?php phpinfo(); ?>

Open in new window

Upload this file to your server and then load this page in your browser. Search for two values -- one for post_max_size and one for upload_max_filesize. These may be preventing your file from being processed. Be sure to remove this file from your server after use. It contains information you don't want everyone to know.

Oddly enough, the file file size may not be determined until after the upload at which point it is discarded if it's too big. See the following PHP reference to help with max file size:
http://us2.php.net/features.file-upload
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

dmgroomCommented:
1) How large a file are you trying to upload?  The max file size in your form is set to 20Mb, but this may be much larger than the  size set in php.ini.

Have you tried uploading a small file, say a few hundred Kb in size?

2) Im surprised to see the lines
// Create directory if necessary
if(!file_exists('uploads')) mkdir('uploads');

Open in new window

If you need the uploads directory why not just create the directory manually and set its permissions .

3)  In  
// Move the file
if(move_uploaded_file($_FILES['thefile']['tmp_name'],
'uploads/' . $_FILES['thefile']['name'])) {

Open in new window

 try replacing 'uploads/'  with the aboslute path to the uploads directory
0
DrDamnitCommented:
@Ray:

I have NO SHAME when it comes to GoDaddy and their servers. Last time I checked, they were a full MAJOR version of PHP behind what is generally used. (They were still on PHP 4 not long ago). They have some silly / wired configs over there too.

Very rarely will I tell a fellow EE'er to contact support... but I have found that with GoDaddy... it is usually a shortcut to save a lot of headaches. After support confirms that there is nothing "stupid" going on on their side, then we can all jump in.

Of course, that was before the MIGHTY and MASTERFUL <angelic_music> ray_pasuer</angelic_music> jumped in. I bow before thee so the weight of your 9,000,000 PHP points does not squash me like a bug. :-)

Hope you're doing well. We haven't collaborated on a question in a while. I always look forward to your elegant solutions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jbpeakeAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.