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
https://forums.phpfreaks.com/topic/116845-file-not-uploading/
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
https://forums.phpfreaks.com/topic/116845-file-not-uploading/#findComment-600909
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.