dragonscrapper Posted March 17, 2014 Share Posted March 17, 2014 I need some help. I am trying to do an assignment, but I am getting nowhere. It says to create a Web Form for uploading pictures for a high school reunin. The form should have text input fields for the person's name and a description of the image, and a file input field for the image. To accompany each image file, create a text file that contains the name and description of the image. Create a separate Web page that displays the pictures with a caption showing the name and description fields. Ensure that the Projects directory has read and write permissions for everyone. The HTML I have is: <form action="" method="post" enctype="multipart/form-data"name="uploadImage" id="uploadImage"><p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <label for="image">Upload image:</label> <input type="file" name="image" id="image" /></p><p> <input type="submit" name="upload" id="upload"value="Upload" /></p></form> The PHP I have is: <?php define ('MAX_FILE_SIZE', 1024 * 50); if (array_key_exists('upload', $_POST)) { define('UPLOAD_DIR', '/path/to/images/'); $file = str_replace(' ', '_', $_FILES['image']['name']); $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg','image/png'); if (in_array($_FILES['image']['type'], $permitted) && $_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) { switch($_FILES['image']['error']) { case 0: if (!file_exists(UPLOAD_DIR . $file)) { $success =move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR .$file); } else { $result = 'A file of the same name already exists.'; } if ($success) { $result = "$file uploaded successfully."; } else { $result = "Error uploading $file. Please try again."; } break; case 3: case 6: case 7: case 8: $result = "Error uploading $file. Please try again."; break; case 4: $result = "You didn't select a file to be uploaded."; } } else { $result = "$file is either too big or not an image."; }}?> It is not working properly. The html file will load but when I click Submit, it just clears the field and refreshes the page. I am very much a beginner to php so I am in no way a professional. Can someone help me please? Also, how would I do the second web page to list the pics? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 18, 2014 Share Posted March 18, 2014 The html file If the HTML file has PHP code in it then it should end with a .php extension, not a .html extension. Quote Link to comment Share on other sites More sharing options...
dragonscrapper Posted March 24, 2014 Author Share Posted March 24, 2014 Ok I think I understand it. So I would not have a html file and a php file? I would have just one php file with everything in it? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 25, 2014 Share Posted March 25, 2014 Yes you could do. Or you could separate your code into multiple php files and then just include them when needed Quote Link to comment Share on other sites More sharing options...
nodirtyrockstar Posted March 25, 2014 Share Posted March 25, 2014 Just in case you still need further clarification, Ch0cu3r is right that you don't need both. You can write HTML to the screen with PHP, most commonly like so: echo "<h1>HTML</h1>"; Quote Link to comment 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.