Khoroshko Posted August 24, 2013 Share Posted August 24, 2013 <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { foreach($_REQUEST as $key => $val) { echo $key, " : ", $val, "<br />"; } } else { ?> <form action="test.php" method="post"> <label for="username">Username:</label> <input type="text" name="username" /> <label for="email">Email:</label> <input type="text" name="email" /> <input type="submit" value="Register!" /> </form> <?php } // End else statement ?> ------------ <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { // Checks if a file was uploaded without errors if(isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name']) && $_FILES['photo']['error']==UPLOAD_ERR_OK) { // Outputs the contents of $_FILES foreach($_FILES['photo'] as $key => $value) { echo "$key : $value <br />"; } } else { echo "No file uploaded!"; } } else { // If the form was not submitted, displays the form HTML ?> <form action="test.php" method="post" enctype="multipart/form-data"> <label for="photo">User Photo:</label> <input type="file" name="photo" /> <input type="submit" value="Upload a Photo" /> </form> <?php } // End else statement ?> -------------- <?php // Checks if the form was submitted if($_SERVER['REQUEST_METHOD'] == 'POST') { // Checks if a file was uploaded without errors if(isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name']) && $_FILES['photo']['error']==UPLOAD_ERR_OK) { // Checks if the file is a JPG image if($_FILES['photo']['type']=='image/jpeg') { $tmp_img = $_FILES['photo']['tmp_name']; // Creates an image resource $image = imagecreatefromjpeg($tmp_img); // Tells the browser what type of file header('Content-Type: image/jpeg'); // Outputs the file to the browser imagejpeg($image, '', 90); // Frees the memory used for the file imagedestroy($image); } else { echo "Uploaded file was not a JPG image."; } } else { echo "No photo uploaded!"; } } else { // If the form was not submitted, displays the form HTML ?> <form action="test.php" method="post" enctype="multipart/form-data"> <label for="photo">User Photo:</label> <input type="file" name="photo" /> <input type="submit" value="Upload a Photo" /> </form> <?php } // End else statement ?> ----------------- Reading: PHP for the Absolute Beginner Using dreamweaver cs6 and xampp The first thing is a submit form to create an account in the book. I copied it exactly from the book at this point and it still does not work. I get this when I submit the form on localhost " Object not found!The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 10.0.0.3Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1" "The book is no help.Second thing is the first part about image uploading, third is the second bit about it. I ended up copying exactly from the book to see if my typing (which was the exact same) did not work. I get on chrome - a little image of a paper with a broken edge, I guess broken file or no file? Firefox - "No file uploaded! No photo uploaded!" They say that it should work in the book. Can someone help?I'm so new to PHP that all my looking on the internet was just looking at things I'm barely familiar with. Quote Link to comment https://forums.phpfreaks.com/topic/281520-reading-a-book-and-lost-on-how-to-make-these-scripts-directly-from-the-book-work/ Share on other sites More sharing options...
AbraCadaver Posted August 24, 2013 Share Posted August 24, 2013 In each of those files, change the filename in <form action="test.php"... to the actual name of the file it is in. Quote Link to comment https://forums.phpfreaks.com/topic/281520-reading-a-book-and-lost-on-how-to-make-these-scripts-directly-from-the-book-work/#findComment-1446572 Share on other sites More sharing options...
Khoroshko Posted August 24, 2013 Author Share Posted August 24, 2013 It is test.php It's localhost/simple_blog/test.php Everything is in the folder simple_blog Quote Link to comment https://forums.phpfreaks.com/topic/281520-reading-a-book-and-lost-on-how-to-make-these-scripts-directly-from-the-book-work/#findComment-1446575 Share on other sites More sharing options...
Khoroshko Posted August 24, 2013 Author Share Posted August 24, 2013 Also if I put a .png file in the submit photo box, it returns this name : acc323.png type : image/png tmp_name : C:\xampp\tmp\php7224.tmp error : 0 size : 3675 Uploaded file was not a JPG image. like it should. so why not show the image? Quote Link to comment https://forums.phpfreaks.com/topic/281520-reading-a-book-and-lost-on-how-to-make-these-scripts-directly-from-the-book-work/#findComment-1446576 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.