arunpatal Posted December 20, 2012 Share Posted December 20, 2012 Hello everyone, I am trying to build shopping via dreamweaver...... right now i am working on admin area..... Till now it was easy to view, edit and add data from/to database But now i want to make 4 image field which upload the image to a folder in server and add the name of this uploaded file in to database field... please explain if it can be done easily by dreamweaver Thanks Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/ Share on other sites More sharing options...
Christian F. Posted December 21, 2012 Share Posted December 21, 2012 (edited) No, it can't. You need to sit down and actually learn how to program in PHP, including all of the necessary security-measures you need to take when making a webshop solution. Due to the massive amount of work needed, and not to mention the high degree of security necessary, I only recommend writing your own as an exercise. Never, ever, write something for public use. Instead go with a premade webshop solution, like Magento, OpenCart, or the Wordpress/Joomla plugins. A lot easier to set up, and not to mention properly secured from the start. PS: No amount of PHP programming can be done "easily" in DreamWeaver. PHP (as well as other dynamic scripting/programming languages) are not compatible with code-generators. Pretty much for the same reason that one pair of shoes doesn't fit everyone; Each situation has its own unique needs and prerequisites, which the code generators are not equipped to handle. A program is a dumb thing, it can only do what it's been explicitly told to do. Programming requires an understanding of the problem, something which in turn requires intelligence. We're not quite at A.I. levels yet. Edited December 21, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1400691 Share on other sites More sharing options...
arunpatal Posted December 21, 2012 Author Share Posted December 21, 2012 (edited) No, it can't. You need to sit down and actually learn how to program in PHP, including all of the necessary security-measures you need to take when making a webshop solution. Due to the massive amount of work needed, and not to mention the high degree of security necessary, I only recommend writing your own as an exercise. Never, ever, write something for public use. Instead go with a premade webshop solution, like Magento, OpenCart, or the Wordpress/Joomla plugins. A lot easier to set up, and not to mention properly secured from the start. PS: No amount of PHP programming can be done "easily" in DreamWeaver. PHP (as well as other dynamic scripting/programming languages) are not compatible with code-generators. Pretty much for the same reason that one pair of shoes doesn't fit everyone; Each situation has its own unique needs and prerequisites, which the code generators are not equipped to handle. A program is a dumb thing, it can only do what it's been explicitly told to do. Programming requires an understanding of the problem, something which in turn requires intelligence. We're not quite at A.I. levels yet. I agree what you wrote...... i am not in IT field professionally but trying to learn basic of php... I learn little php few month ago but could not repeat those exercises I think i should start again from A of php programming and make my basic strong...... Edited December 21, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1400758 Share on other sites More sharing options...
Christian F. Posted December 22, 2012 Share Posted December 22, 2012 Hehe, sounds like a good plan indeed. Glad I could help you out on this, and if you have any more questions you know where to ask. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1400867 Share on other sites More sharing options...
arunpatal Posted December 22, 2012 Author Share Posted December 22, 2012 Hehe, sounds like a good plan indeed. Glad I could help you out on this, and if you have any more questions you know where to ask. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1400899 Share on other sites More sharing options...
twistedvengeance Posted December 24, 2012 Share Posted December 24, 2012 Despite how long and hard I worked on this, I'll give you the beginning of what you need. This will not insert any information into a database. Also, the top part of this is on google. <?php $uploaded = false; $name = 1; if(isset($_POST['Upload'])){ $allowedExts = array("jpg", "jpeg", "png", "gif"); $extension = end(explode(".", $_FILES["file"]["name"])); if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")){ if($_FILES["file"]["size"] < 2000000){ if(in_array($extension, $allowedExts)){ if ($_FILES["file"]["error"] > 0){ echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; }else{ $_FILES["file"]["name"] = $name . ".jpg"; while(file_exists("template/gallery/" . $_FILES["file"]["name"])){ $name++; $_FILES["file"]["name"] = $name . ".jpg"; } while(file_exists("template/php/user/uploaded/" . $_FILES["file"]["name"])){ $name++; $_FILES["file"]["name"] = $name . ".jpg"; } $location = "template/php/user/uploaded/"; move_uploaded_file($_FILES["file"]["tmp_name"], "$location" . $_FILES["file"]["name"]); echo "Thanks for uploading!"; echo "<a href=\"$location$name.jpg\">Click to see</a>"; $uploaded = true; } }else{ echo "Invalid file"; } }else{ echo "File is too big!"; } }else{ echo "Invalid File Type"; } } if($uploaded == false){?> <div id="posts"> <form method="post" action="" enctype="multipart/form-data" name="form1"> <span>Picture:</span> <input name="file" type="file" class="box"/> <input type="submit" id="mybut" value="Upload" name="Upload"/> </form> <span>Only JPG(JPEG) files allowed.</span> </div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1401144 Share on other sites More sharing options...
PFMaBiSmAd Posted December 24, 2012 Share Posted December 24, 2012 @twistedvengeance, Reposting bad generic upload code that doesn't address what the OP asked, is not helpful The upload code you found, is based on the w3schools code and tests for upload errors AFTER it tries to use some of the uploaded file information. Therefore, it reports the wrong reason why the upload was not accepted and never reports actual upload errors. You must test if the upload worked BEFORE you can reference any of the uploaded file information. Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1401147 Share on other sites More sharing options...
twistedvengeance Posted December 25, 2012 Share Posted December 25, 2012 @twistedvengeance, Reposting bad generic upload code that doesn't address what the OP asked, is not helpful The upload code you found, is based on the w3schools code and tests for upload errors AFTER it tries to use some of the uploaded file information. Therefore, it reports the wrong reason why the upload was not accepted and never reports actual upload errors. You must test if the upload worked BEFORE you can reference any of the uploaded file information. Aside from the fact that I gave him 99% of what he needs, nothing with this code is wrong. I have re-coded this so it works properly. Don't be an ass if you don't have the desire to try and help someone out. Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1401234 Share on other sites More sharing options...
Christian F. Posted December 25, 2012 Share Posted December 25, 2012 I assume you wouldn't be too happy with me if I showed up on your door with a sledgehammer and started banging on your walls, wreaking havoc on it, if you asked me to help you widen the door frame so that you could get a new door into place. Though, considering your post you'd be an ass if you told me to stop because I was doing it wrong. See anything wrong with that picture? For the record: Your code is wrong. You don't handle any errors in it, you don't validate the input, you don't redirect the user after a completed upload (to prevent the reload-resubmit problem), the code is messy, and incorporates a lot of bad logic and anti-patterns. It might seem to be working as desired, but that's only by coincidence rather than design. Quote Link to comment https://forums.phpfreaks.com/topic/272232-upload-the-image-to-a-folder-in-server/#findComment-1401238 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.