onthespot Posted July 25, 2009 Share Posted July 25, 2009 Hey guys, I am looking into allowing users to upload images to their profiles. This function of course could be used anywhere on my site tha requires images. So I need a user to be able to upload an image, and then it is displayed on their profile. The image should only be a certain size, 120 x 140 and a jpeg. And if a new image is uploaded, it should overwrite the previous one. For the image resizing, would I just set the space I want the image to display to the size I want? Or is there a more effect method? Quite confused about this, would appreciated it A LOT if someone could help me out here. Really don't know where to even begin! Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/ Share on other sites More sharing options...
Garethp Posted July 25, 2009 Share Posted July 25, 2009 Begin here. http://www.w3schools.com/PHP/php_file_upload.asp Then move on to http://www.tutorialhero.com/tutorial-44915-php_image_manipulation_with_gd2.php If you want someone to write the script for you, post here http://www.phpfreaks.com/forums/index.php/board,8.0.html Or PM a user here you think would help you Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/#findComment-882617 Share on other sites More sharing options...
onthespot Posted July 25, 2009 Author Share Posted July 25, 2009 cheers mate, dont want anyone to write it for me, wanted some direction as you have given me, thanks Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/#findComment-882628 Share on other sites More sharing options...
onthespot Posted July 25, 2009 Author Share Posted July 25, 2009 I have a question, atm, i have the following form. <table> <tr><td><form action="" method="POST"> <p><u>Create a News Piece</u> <p>Subject:<input name="subject" type="text"> <p>Comment:<textarea name="comment" rows="4" cols="65" ></textarea> <p><input type="submit" name="submit" value="Add News"> </form></tr></td> </table> I want to add a new input on the form for an image. However having read the above pages, it states the form must be enctype="multipart/form-data" . If I add that to the above form, will it stop it working? Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/#findComment-882641 Share on other sites More sharing options...
onthespot Posted July 25, 2009 Author Share Posted July 25, 2009 So this is what i have atm. <table> <tr><td><form action="" method="POST" enctype="multipart/form-data"> <p><u>Create a News Piece</u> <p>Subject:<input name="subject" type="text"> <p>Comment:<textarea name="comment" rows="4" cols="65" ></textarea> <p>Image: <input type="file" name="file" id="file" /> <p><input type="submit" name="submit" value="Add News"> </form></tr></td> </table> Thats the form to enter. <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> And thats the php for the uploaded image. The image however, just wont upload. Doing absolutely nothing at all, although the rest of the form is working correctly. Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/#findComment-882648 Share on other sites More sharing options...
Garethp Posted July 25, 2009 Share Posted July 25, 2009 Try if(move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"])) { echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } else { echo "Could not upload"; } Link to comment https://forums.phpfreaks.com/topic/167389-image-upload/#findComment-882662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.