Jump to content

Form Upload - Can someone please proof read?


Mr Chris

Recommended Posts

Hi all,

 

I've created a form whereby I want to upload images and pass a story_id onto the next page (uploader.php)

 

Now i've got it working so it passes the story_id, but the images don't longer upload and I get the message:

 

There was an error uploading the file, please try again

 

I can’t see what’s wrong though.  Can anyone please help as i'm stumped as I think it should work?

 

Thanks

 

Chris

 

upload.php

<?
if($_POST["x"] == "Upload"){
$story_id = $_POST['story_id'];
header("Location: uploader.php?story_id=$story_id");
}
?>
<form action="" method="post" enctype="multipart/form-data">
    
    <input type='hidden' name='story_id' value='<?php echo $_GET['story_id'];?>' />
    <input type='hidden' name='MAX_FILE_SIZE' value='25000000'>
    File 1: 
    <input type='file' name='uploadedfile' size='30'></p>
  ;; 
  <p> Video Credit: 
    <INPUT TYPE="text" SIZE="48" MAXLENGTH="255" NAME="video_credit" <?php if(isset($video_credit)) echo "value='$video_credit'"; ?>/>
    // </p>
    
  <p>Video Caption: 
    <INPUT TYPE="text" SIZE="48" MAXLENGTH="255" NAME="video_caption" <?php if(isset($video_caption)) echo "value='$video_caption'"; ?>/>
    <br>
    <br>
        <INPUT TYPE="submit" VALUE="Upload" NAME="x"> 
  </p>
    <p>
  </p>
</form>

 

However, despite this the image now will not upload.

 

uploader.php

<?php
$target_path = "video/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

// Start the connection to the database 

        include('*********');
        $can_i_connect = db_connect(); // by db_connect function is in my include file 
        if(!$can_i_connect) 
        { 
            $msg = "Could not connect to the database";
        } 

// End the connection to the database  

    // insert into database
    $date_uploaded = date("m d, Y");
    $directory = "video/";
    $file_name = basename( $_FILES['uploadedfile']['name']);
    $video_caption = stripslashes(trim($_POST['video_caption']));
    $video_credit = stripslashes(trim($_POST['video_credit']));
    $story_id = $_GET['story_id']; 

    $sql_query = mysql_query("INSERT INTO cms_videos (date_uploaded,directory,file_name,video_caption,video_credit,story_id) VALUES ('$date_uploaded','$directory','$file_name','$video_caption','$video_credit','$story_id')");
    if (!$sql_query) {
        exit("<p>Error performing query: " . mysql_error() . "</p>");

    }
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

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.