meow Posted July 3, 2008 Share Posted July 3, 2008 Hey everyone, I'm pretty new to PHP and would appreciate some help with an image upload script that I'm working on. I lifted it from a tutorial but I've been trying to customize it to suit my needs. I have a nice little form: <form enctype="multipart/form-data" method="post"> <table cellpadding="8"> <tr> <td><label for="title">title:</label></td> <td><input type="text" name="title" /></td> </tr> <tr> <td><label for="description">description:</label></td> <td><textarea name="description" rows="4" cols="35"></textarea></td> </tr> <tr> <td><label for="image">image file:</label></td> <td><input type="file" name="image" /></td> </tr> <tr> <td><label for="author" maxlength="30">your name:</label></td> <td><input type="text" name="author"></td> </tr> <tr> <td><label for="email">your email:</label></td> <td><input type="text" name="email"></td> </tr> <tr> <td colspan="2"><input type="submit" value="Submit" /></td> </tr> </table> </form> and this script: <? if(isset($_FILES["image"])){ $file = $_FILES['image']; $title = htmlspecialchars($_POST["title"]); $description = htmlspecialchars($_POST["description"]); $author = htmlspecialchars($_POST["author"]); $email = htmlspecialchars($_POST["author"]); $date = date('F jS, Y'); $basename = date("d-m-Y-G-j-s-").basename($file['name']); if($file['type'] == 'image/gif' || $file['type'] == "image/jpeg" || $file['type'] == "image/pjpeg" || $file['type'] == 'image/png'){ if(move_uploaded_file($file['tmp_name'], "/path/to/public_html/wallpapers/".$basename) && mysql_query("INSERT INTO wallpapers (id, title, description, image, author, email, date, basename) VALUES('', '$title', '$description', 'http://www.url.com/wallpapers/$basename', '$author', '$email', '$date', '$basename')") or die(mysql_error())){ echo "<p>thanks! see your submission <a href='view.php?id=$id'>here</a>.</p>"; } else { "<p>sorry, there was an error!</p>"; } }//is an image else { echo "<p>that wasn't an image!</p>"; }//isn't image }//end isset file else { echo "<p>all fields are required!</p>"; } ?> I would like to a) create and save a thumbnail of the image as they are uploaded whose path I would be able to call from the MySQL database, b) make sure the user has not left any fields empty, and c) redirect or link the user to their submitted image. I realize that this is a lot to ask but I would really appreciate it if someone could help me. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/113032-need-help-with-a-couple-of-things-image-upload-script/ Share on other sites More sharing options...
CMC Posted July 3, 2008 Share Posted July 3, 2008 Ok, checking empty values is easy enough. Just use the empty() function. ex: if(empty($title)){ $errors[] = 'Please input a title'; } Then you can check $errors using: if(!empty($errors)){ foreach($errors as $msg){ echo $msg.'<br />'; } die(); }else{ run rest of script... } For the thumbnails, look into the GD Image Libary: http://www.php.net/gd http://www.phpgd.com/ Also, here's a tutorial that instructs you through creating thumbnails and resizing images. http://www.phpit.net/article/image-manipulation-php-gd-part1/ http://www.phpit.net/article/image-manipulation-php-gd-part2/ Link to comment https://forums.phpfreaks.com/topic/113032-need-help-with-a-couple-of-things-image-upload-script/#findComment-580639 Share on other sites More sharing options...
meow Posted July 3, 2008 Author Share Posted July 3, 2008 Thanks for the response! Is there any way I can check multiple values at the same time to avoid a lot of nested if...else statements? Link to comment https://forums.phpfreaks.com/topic/113032-need-help-with-a-couple-of-things-image-upload-script/#findComment-580641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.