|
ninethousandfeet
|
Mar 25 2009, 01:22 PM
Post #1
|
|
- Posts:
- 1
- Group:
- Members
- Member
- #79
- Joined:
- Mar 25, 2009
|
first off, i want to introduce myself and say thank you for having me... i was referred to this forum from a user in a php forum elsewhere... if there are any unique features that people prefer on this forum, then please feel free to let me know so that i can adapt.
what brings me here is that i am having trouble with uploading an image to my directory... i believe the file name is being uploaded to my db okay, but nothing is showing up on my directory. in case you are wondering, i have checked my settings with my host and they are A-okay. i'm stuck. any recommendations would be more then helpful. here is what i have:
- Code:
-
$editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); }
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // define a constant for the maximum upload size define ('MAX_FILE_SIZE', 51200); if (isset($_FILES['image_data'])) { // define constant for upload folder define('UPLOAD_DIR', '/domains/mysite.com/public_html/upload'); // replace any spaces in original filename with underscores // at the same time, assign to a simpler variable $file = str_replace(' ', '_', $_FILES['image_data']); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image_data/gif', 'image_data/jpeg', 'image_data/pjpeg', 'image_data/png'); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false;
// check that file is within the permitted size if ($_FILES['image_data']['size'] > 0 && $_FILES['image_data']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; }
// check that file is of a permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['image_data']['type']) { $typeOK = true; break; } }
if ($sizeOK && $typeOK) { $success = move_uploaded_file($_FILES['image_data']['tmp_name'], UPLOAD_DIR.'/'.$file); }
$insertSQL = sprintf("INSERT INTO postingTable (post_id, post_title, product_name, user_id, post_date, buy_or_share, category_name, image_data) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['post_id'], "int"), GetSQLValueString($_POST['post_title'], "text"), GetSQLValueString($_POST['product_name'], "text"), GetSQLValueString($_POST['user_id'], "int"), GetSQLValueString($_POST['post_date'], "defined", 'NOW()'), GetSQLValueString($_POST['buy_or_share'], "text"), GetSQLValueString($_POST['category_name'], "text"), GetSQLValueString($_FILES['image_data'], "text")); mysql_select_db($database_connUser, $connUser); $Result1 = mysql_query($insertSQL, $connUser) or die(mysql_error());
$insertGoTo = "userprofile.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } } ?> doctype... my form: <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Post title:</td> <td><input type="text" name="post_title" value="" size="50" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right" valign="top">Product/Store Names:</td> <td><textarea name="product_name" cols="50" rows="5"></textarea></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Category:</td> <td><select name="category_name"> <option value="other" <?php if (!(strcmp("other", ""))) {echo "SELECTED";} ?>>Other</option> </select></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Add Picture:</td> <td><input type="file" name="image_data" value="" size="40" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input name="post" type="submit" id="post" value="post" /></td> </tr> </table> <input type="hidden" name="post_id" value="" /> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="hidden" name="user_id" value="<?php echo $row_getUser['user_id']; ?>" /> <input type="hidden" name="post_date" value="NOW()" /> <input type="hidden" name="buy_or_share" value="buy" /> <input type="hidden" name="MM_insert" value="form1" />
|