Jump to content

File not uploading


ded

Recommended Posts

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);

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.