deansaddigh Posted April 7, 2010 Share Posted April 7, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/197891-i-cant-get-my-upload-form-to-work/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 7, 2010 Share Posted April 7, 2010 For debugging purposes, add the following lines of code right after the first opening <?php tag - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/197891-i-cant-get-my-upload-form-to-work/#findComment-1038508 Share on other sites More sharing options...
deansaddigh Posted April 8, 2010 Author Share Posted April 8, 2010 Ive added ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); Whats it meant to do, doenst seem to display anything? Quote Link to comment https://forums.phpfreaks.com/topic/197891-i-cant-get-my-upload-form-to-work/#findComment-1038970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.