Jump to content

i cant get my upload form to work!


deansaddigh

Recommended Posts

Hi i have this form

 echo '<form id="two" enctype="multipart/form-data" action="student_photo_uploader.php" method="POST">';
					echo '<input type="hidden" name="MAX_FILE_SIZE" value="999999999999" />';
					echo '<fieldset>';
					echo '<legend>Choose an image:</legend>';
					echo '<input name="uploadedfile" type="file" /><br />';
					echo '<input type="submit" value="Upload File" />';
					echo '</fieldset>';
					?>
        

 

And then i have this page which should upload but its just displaying "there was an error"

<?php
include("includes/connection.php");


            	


    // Where the file is going to be placed 
    $studentimage = "studentImages/";

//This path will be stored in the database as it does not contain the filename
$currentdir = getcwd();
$path = $currentdir . '/' . $studentimage;



//Use this path to store the path of the file in the database.
echo $filepath = $studentimage;


//Create the folder if it does not already exist
if(!file_exists('studentimages'))
    {
        if(mkdir('studentimages'))
        {
            echo 'Folder ' . 'studentImages' . ' created.';
        }
        else
        {
            echo 'Error creating folder ' . 'studentImages';
        }
    }


//Store the folder for the course title.
    if(!file_exists( $filepath ))
    {
        if(mkdir( $filepath ))
        {
            echo 'Folder ' .  $studentimage . ' created.';
        }
        else
        {
            echo 'Error creating folder ' .  $studentimage;
        }
    }


// Where the file is going to be placed 
    $target_path = $filepath;

    // Add the original filename to our target path. Result is "uploads/filename.extension"
    $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";
	$filename =  $_FILES['uploadedfile']['name'];

	//Store the filename, path other criteria in the database 
	$query = "INSERT INTO studentphotos(image_id, name, path)
	VALUES(0, '$filename', '$filepath')";

	//Perform the query
	$add = mysql_query($query, $conn)
		or die("Unable to add the image details to the database");
	$imageid = mysql_insert_id();


	$message = 'Upload Successful';
	//Close the connection to the database	
	mysql_close($conn);
	header("Location:  add_student_photos.php? message=$message");
	exit();
} 
else
{	
	$message = 'There was an error uploading the file, please try again!';

	//Close the connection to the database	
	mysql_close($conn);
	header("Location:add_student_photos.php? message=$message");
	exit();
}
?>

 

Can anyone help me see what i have done wrong please.

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/197891-i-cant-get-my-upload-form-to-work/
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.