joseph_ccc Posted October 17, 2009 Share Posted October 17, 2009 Hi, This is my "add_file.php" actually it works (adding the right file to my databasae), but It does not display the error messages if the file is not upload because is not in the right format. I think I mess up with the curly brackets and that's why doesn't display the error?. Sorry, I am a novice in programming, any help will be appreciate it. <?php # add_file.php // This page allows users to upload files to the server. // Set the page title and include the HTML header. $page_title = 'Projects Files'; include ('./header.html'); $name = $_FILES ['file']['name']; $size = $_FILES ['file']['size']; $type = $_FILES ['file']['type']; $temp = $_FILES ['file']['tmp_name']; $d = $_POST ['description']; $error = $_FILES ['file']['error']; // Check if the form has been submitted. if (isset($_FILES['upload'])) { // Check if the file is a .XMIND form if ($type == 'application/vnd.xmind.workbook') { require_once('./mysql_connect.php'); // Connect to the database. // Add the record to the database. $query = "INSERT INTO files (file_name, file_size, file_type, description) VALUES ('$name', '$size', '$type', '$d')"; $result = mysql_query ($query); // Return the files_id from the database. if ($result) { $files_id = mysql_insert_id(); // Move the file . if(move_uploaded_file($temp,"xmind/".$files_id)) { //Couldn't move the file. echo '<p><font color="red">The file cannot be upload. Please try again.</font></p>'; } } } } ?> <br /> <h2 style="text-align:center">Insert a .Xmind File</h2> <br /> <form id="add" method="post" enctype="multipart/form-data"> <fieldset id="add"><legend>Insert a file:</legend> <input type="hidden" name="upload" value="1"> <p><label for="file"><b>File:</b></label></p><input type="file" name="file"> <p><label for="description"><b>Description:</b></label></p> <textarea name="description" cols="40" rows="5"></textarea><br /> </fieldset><br /> <input id="submit" type="submit" value="upload"> </form> <?php include ('./footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/178045-upload-file-and-give-message-error/ Share on other sites More sharing options...
ialsoagree Posted October 17, 2009 Share Posted October 17, 2009 You're not telling PHP to report an error if the file type is wrong: if ($type == 'application/vnd.xmind.workbook') { This if statement doesn't have an else statement, so if the file type is wrong, PHP doesn't do anything. Link to comment https://forums.phpfreaks.com/topic/178045-upload-file-and-give-message-error/#findComment-938829 Share on other sites More sharing options...
joseph_ccc Posted October 18, 2009 Author Share Posted October 18, 2009 I add the else statement, but it doesn't work either. Any ideas? <?php # add_file.php // This page allows users to upload files to the server. // Set the page title and include the HTML header. $page_title = 'Projects Files'; include ('./header.html'); $name = $_FILES ['file']['name']; $size = $_FILES ['file']['size']; $type = $_FILES ['file']['type']; $temp = $_FILES ['file']['tmp_name']; $d = $_POST ['description']; $error = $_FILES ['file']['error']; // Check if the file is a .XMIND form if ($type == 'application/vnd.xmind.workbook') { if ($error > 0 ) { die ('Error uploading file! Code $error.'); } else { if (isset($_POST['upload'])) { // Handle the form. require_once('./mysql_connect.php'); // Connect to the database. // Add the record to the database. $query = "INSERT INTO files (file_name, file_size, file_type, description) VALUES ('$name', '$size', '$type', '$d')"; $result = mysql_query ($query); // Return the files_id from the database. if ($result) { $files_id = mysql_insert_id(); // Move the file . move_uploaded_file($temp,"xmind/".$files_id); } echo '<h3>File has been uploaded!.</h3>'; exit; } } } else { echo '<h2><font color="red">no the right type.</font></h2>'; } ?> <div id="container"> <br /> <h2 style="text-align:center"><img id="xmind" height="48" width="48" alt="image of radcliffe camara in oxford" src="images/xmind-icon.png" title="Xmind icon" />Insert a .Xmind File</h2> <br /> <form id="add" method="post" enctype="multipart/form-data"> <fieldset id="add"><legend>Insert a file:</legend> <input type="hidden" name="upload" value="1"> <p><label for="file"><b>File:</b></label></p><input type="file" name="file"> <p><label for="description"><b>Description:</b></label></p><textarea name="description" cols="40" rows="5"></textarea><br /> </fieldset><br /> <input id="submit" type="submit" value="upload"> </form> </div> <?php include ('./footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/178045-upload-file-and-give-message-error/#findComment-939120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.