kidintraffic Posted April 26, 2007 Share Posted April 26, 2007 I am relatively new to php with using mysql databases, so bare with me. I have a form that a user imputs their data into and when then click submit it uploads that information to the database. I have another page that displays the data. I want to allow the user to be able to upload an image and then I need to display the image on another page. How do I store the image name into the database and also allow the user to upload to the site? Any help is greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/ Share on other sites More sharing options...
tauchai83 Posted April 27, 2007 Share Posted April 27, 2007 hi, there was some people who was faced with that problem before. Please google it out first in this forum. Basic idea for you: store the image path in the DB. <input name="fleImage" type="file" id="fleImage"> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/#findComment-239665 Share on other sites More sharing options...
kidintraffic Posted April 27, 2007 Author Share Posted April 27, 2007 I understand that I have to store just the file name in the database. But I don't understand the process of allowing the user to upload their image to a certain directory. Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/#findComment-239762 Share on other sites More sharing options...
tauchai83 Posted April 28, 2007 Share Posted April 28, 2007 have you test my code that i posted before? Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/#findComment-240144 Share on other sites More sharing options...
kidintraffic Posted April 28, 2007 Author Share Posted April 28, 2007 No cause I don't understand the process in allowing a user to upload a file. Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/#findComment-240592 Share on other sites More sharing options...
tauchai83 Posted April 29, 2007 Share Posted April 29, 2007 The first thing. You create a form. form1.php <form action="form2.php" method="post" name="frmAddImage" > <table> <tr> <td width="150">Image</td> <td> <input name="fleImage" type="file"> </td> </tr> </table> form2.php is the next page for processing. Now form2.php $image = $_FILES[$fileImage]; OR OR OR you can create a function that enable a user to upload the file. example: <?php function uploadImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']]; // generate a random new file name to avoid name conflict $imagePath = md5(rand() * time()) . ".$ext"; list($width, $height, $type, $attr) = getimagesize($image['tmp_name']); // make sure the image width does not exceed the // maximum allowed width if (LIMIT_PRODUCT_WIDTH && $width > MAX_IMAGE_WIDTH) { $result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_IMAGE_WIDTH); $imagePath = $result; } else { $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); } if ($result) { // create thumbnail $thumbnailPath = md5(rand() * time()) . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH); // create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; } else { $thumbnailPath = $result; } } else { // the product cannot be upload / resized $imagePath = $thumbnailPath = ''; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); } ?> the ALL capital letter is defined as constant. such as MAX_IMAGE_WIDTH. try first and think. thanks. I hope this can guide you to the correct direction. There are many other ways to do the same thing. Link to comment https://forums.phpfreaks.com/topic/48770-solved-newb-image-upload/#findComment-240783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.