I am trying to upload a image from my computer to the "Image" Folder created in C:\wamp\www\.(My Document root is set to C:/wamp/www//test) & when I run this program it should display the image in the same browser window.But the following code is not working- <html> <head><title>Upload Files</title> </head> <body> </br> <center> <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="img"/><br> <input type="submit" value="click to upload" name="sub"> </form> <? php if(isset($_POST['sub'])) { $file=$_FILES["img"]["name"]; $dir="images/"; $tot_dir=$dir.$file; if(move_uploaded_file($_FILES["img"]["tmp_name"],$tot_dir)) { ?> <img src="images/<?php echo $file; ?> "border="0" /> <?php } ?> </center> </body> </html> Any suggestion what is wrong with the above code? Any help would be greatly appreciated. Thanks
Hello, Modify your code with the following code. You were missing with a closing for if block and an additional space for <?php tag... Also check folder permission. <html> <head> <title>Upload Files</title> </head> <body> </br> <center> <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="img"/><br> <input type="submit" value="click to upload" name="sub"> </form> <?php if(isset($_POST['sub'])) { $file=$_FILES["img"]["name"]; $dir="images/"; $tot_dir=$dir.$file; if(move_uploaded_file($_FILES["img"]["tmp_name"],$tot_dir)) { ?> <img src="img/<?php echo $file; ?> "border="0" /> <?php } } ?> </center> </body> </html> Code (markup): Hope this will solve your issue. Regards
Yup,Thanks.It's working now.The file is getting uploaded... But one final glitch.The purpose of the above program was to make the image appear in the browser window as well as getting copied into the image folder.... But it's not showing there in the browser
Change <img src="img/<?php echo $file; ?> "border="0" /> to: <img src="<?php echo $tot_dir; ?> "border="0" />
Ok,But why is this ' " ' before border? And, where is the opening ' " ' ends in -> "img/<?php echo $file; ?> "border="0" /> to: OR <img src="<?php echo $tot_dir; ?> "border="0" /> Reply With Quote?
papa_face, the directory name is "images". 11ul, that was a problem with the old code that I didn't realise when changing another part of it. Here is the final version: <img src="<?php echo $tot_dir; ?>" border="0" />
Hi, Also,how to color the browse button? I have tried in many ways to color the "Browse" button using Dreamweaver,but could only color the "Upload" button.I can color the background of the 'textbox' & also the 'Upload' button. If anyone can guide me as to how to change the background-color of the Browse button only,would be very much thankful.
Try this: <input name="submit" type="submit" id="button" value="submit" style="background-color:#000099;"/>
apparently it is impossible to do using CSS. http://lists.evolt.org/archive/Week-of-Mon-20030303/136274.html however, there is an alternative: http://www.quirksmode.org/dom/inputfile.html
adam, i think he was referring to the "Browse" button for the file selection input field (type="file"), not the regular button (type="submit")
Yes,meetgs is absolutely correct.I was referring to the "Browse" button & not the regular "Submit" button. The 'Browse' button has this code - <input name="img" type="file" style="background-color:#33FFFF"> which is giving color to the background of the "input textbox". While the "Submit" button is already colored,the code is- <input type="submit" value="click to upload" name="sub" style="background-color:#9999FF"> I wanted to know how to color the 'browse' button & not the 'Submit'/ 'Upload' which I have already done!! Any suggestions as to how to color the 'Browse' button only? Also,Thanks meetgs for the links.But from the links you have provided,I couldnot make out how to color a browse button? I don't know javascript & quite novice in programming. Please guide me. Thanks
Also,I tried this code as given in your link- input.FormButton { background-color: #b5dcb8; color: #5b4223; font-size: 11px; font-weight: bold; letter-spacing: 1px; padding: 1px; } input.FormText { background-color: #ffffff; color: #000000; border: 1px solid ; } textarea { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } I copied the above code and pasted it after the following code tag- <input name="img" type="file" style="background-color:#33FFFF"> But nothing happened.The above lines are all appearing in the browser!!!
Don't do it. It doesn't degrade well in older browsers, it is hard to use even in modern browsers, it is not worth the effort and so on. File inputs aren't supposed to be styled due to security issues.
you should use <STYLE> tag to define CSS in file like <style type="text/css"> input.FormButton { background-color: #b5dcb8; color: #5b4223; font-size: 11px; font-weight: bold; letter-spacing: 1px; padding: 1px; } input.FormText { background-color: #ffffff; color: #000000; border: 1px solid ; } textarea { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #000000; } </style>