ded Posted July 27, 2008 Share Posted July 27, 2008 Hello all, I am having problems uploading files to a folder. I am getting the "Error: Photo did not upload properly." message everytime. Folder name is pictures w/permissions set at 777 <?php $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("database"); $query = "SELECT * FROM `gallery_categories` ORDER BY `category`"; $result = mysql_query($query,$dbh) or die(mysql_error()); echo "<form enctype=\"multipart/form-data\" action=\"postphoto.php\" method=\"post\">"; echo "<center><select name=categoryid>"; while($row = mysql_fetch_array($result)) { echo "<option value='{$row['rrn']}'>{$row['category']}</option>"; } echo "</select><br><br>"; echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\">"; echo "File to Upload:<input name=\"filename\" type=\"file\"><br><br>"; echo "Photo Caption:<input type=\"text\" name=\"caption\" size=\"50\"><br><br>"; echo "<input type=\"submit\">"; echo "</form></center>"; ?> postphoto.php code <?php $catid = $_POST['categoryid']; $caption = $_POST['caption']; $uploaddir = 'pictures/'; $filename = $_FILES['filename']['name']; $path = $uploaddir . $filename; echo '<pre>'; if (move_uploaded_file($_FILES['filename']['tmp_name'], $path)) { echo "Photo has been uploaded to database"; } else { echo "Error: Photo did not upload properly."; } print "</pre>"; $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("database"); $insert = "INSERT INTO gallery_photos (category, filename, caption) VALUES ('$catid','$filename','$caption')"; $results = mysql_query($insert); ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 27, 2008 Share Posted July 27, 2008 echo out all your varaibles and make sure there correct and add error_reporting(E_ALL); to the top of the pages Quote Link to comment Share on other sites More sharing options...
ded Posted July 27, 2008 Author Share Posted July 27, 2008 Everything echo'd out ok. It is possible that the host has some block on folder that will not allow uploads? I have similar code on another site and it works fine. Quote Link to comment Share on other sites More sharing options...
MFHJoe Posted July 27, 2008 Share Posted July 27, 2008 Everything echo'd out ok. It is possible that the host has some block on folder that will not allow uploads? I have similar code on another site and it works fine. Yes, that could be very possible actually. Especially if a similar code works for you on another site. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2008 Share Posted July 27, 2008 Add both of these lines after your first opening <?php tag to see what error is occurring with the move_uploaded_file() statement - ini_set ("display_errors", "1"); error_reporting(E_ALL); Your code has absolutely no error checking of the upload file status before blindly accessing the upload data. Check the $_FILES['filename']['error'] value - http://www.php.net/manual/en/features.file-upload.errors.php It is also possible that you have exceeded the post_max_size setting, in which case both the $_POST and $_FILES superglobals are empty. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.