I'm having a file uploading issue. It posts all the information to the database except for the file path and doesnt upload the file. I cant seem to find my problem anywhere in the code my self. Hopefully someone might be able to tell me what I'm doing wrong.
heres my php
and heres my upload formPHP Code:<?php
require("../check_login.php");
if(empty($_POST)) {
$status = 'Add New Post';
}
else {
$post_title = addslashes($_POST['post_title']);
$post_content = addslashes($_POST['post_content']);
$destination = '../../attachments';
$attachment = $_FILES['attachment']['name'];
$attachment_tmp_name = $_FILES['attachment']['tmp_name'];
$error_list = array();
if(empty($post_title)) {
$error_list[] = 'You did not supply a Title';
}
if(empty($post_content)) {
$error_list[] = 'You did not supply any Content';
}
if(empty($error_list)) {
require("../../../../connect.php");
$sql = "INSERT INTO blog SET post_title='$post_title', post_content='$post_content', date_posted = NOW(); ";
if(!empty($attachment)) {
if(move_uploaded_file($attachment,"$destination/$attachment")) {
$sql .= ", attachment='$attachment' ";
}
}
if(mysql_query($sql)) {
header('Location: index.php');
}
else {
$status ='Unable to add Post';
}
}
else {
$status = 'Unable to Post';
$status = '<ul>';
foreach($error_list as $error_message) {
$status .= "<li>$error_message</li>";
}
$status .= '</ul>';
}
}
?>
thanks for the help I appreciate it.Code:<form action="post_add.php" method="post" enctype="multipart/form-data"> <dl> <dt><label for="post_title">Title</label></dt> <dd><input type="text" name="post_title" id="post_title" value="<?php echo $post_title; ?>" /></dd> <dt><label for="post_content">Content</label></dt> <dd><textarea name="post_content" id="post_content" rows="10" cols="55"><?php echo $post_content; ?></textarea></dd> <dt><label for="attachment">Attachment</label></dt> <dd><input type="file" name="attachment" id="attachment" /></dd> </dl> <div> <input type="hidden" name="MAX_FILE_SIZE" value="20000" <input type="submit" name="submit" value="Add" /> <input type="reset" name="reset" value="Reset Form" /> </div> </form>



Reply With Quote
Bookmarks