believeinsharing Posted October 20, 2011 Share Posted October 20, 2011 Hi want to upload file using form's input type="file" then i want to display it on another page, As i am new to PHP i am doing this step by step so that I can test each step and go ahead. My first step is to upload file and check if its uploading in temp location.. I got same code from net.. I am using notepad++ thats why not sure abt syntax error, What I did is: <html> <body> <form action="index.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="image"> <input type="submit" value="Upload"> </form> <?php mysql_connection("localhost","root","admin") or die(mysql_error()); mysql_select_db("searchdeals") or die(mysql_error()); echo $file = $_FILES['image']['tmp_name']; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249471-error-while-file-upload/ Share on other sites More sharing options...
gristoi Posted October 21, 2011 Share Posted October 21, 2011 ok, couple of things, why do you need a database connection for this? and is this posting back to index.php, or is index.php another file?. try this: <html> <body> <form action="index.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="myImage"> <input type="submit" value="Upload"> </form> <?php if($_FILES){ echo "Name: " . $_FILES["myImage"]["name"] . "<br />"; echo "Size: " . ( $_FILES["myImage"]["size"] /1024) . "Kb<br />"; echo "Type: " . $_FILES["myImage"]["type"] . " <br />"; echo "temp Directory: " . $_FILES["myImage"]["tmp_name"]; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/249471-error-while-file-upload/#findComment-1281111 Share on other sites More sharing options...
believeinsharing Posted October 21, 2011 Author Share Posted October 21, 2011 @gristoi: Hey thanks its working fine with ur code... I am using database because I wanted to add this image to database in next state and index.php is a same file and I am using it as POST back.. Can u plz tell, wht was the prob in my code.. As I am new to PHP I appreciate ur help which will help to understand basic... Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/249471-error-while-file-upload/#findComment-1281140 Share on other sites More sharing options...
gristoi Posted October 21, 2011 Share Posted October 21, 2011 your problem was with: mysql_connection("localhost","root","admin") or die(mysql_error()); should have been mysql_connect("localhost","root","admin") or die(mysql_error()); if you werent getting any warnings or errors showing then you will need to turn on your error checking. to do this you can put this at the very top of your page: <?php ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); this will help you a lot, by showing you all of the errors and warnings that your code makes. good luck Quote Link to comment https://forums.phpfreaks.com/topic/249471-error-while-file-upload/#findComment-1281153 Share on other sites More sharing options...
believeinsharing Posted October 21, 2011 Author Share Posted October 21, 2011 @gristoi: Got it... thx will remember that and will help me in future... My last question.. lets say my code is: <body> <form action="index2.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="myImage" /> <input type="submit" value="Upload" /> </form> <?php echo $_FILES["myImage"]["tmp_name"]; ?> </body> interesting thing is... this code is working fine in IE but not working in chrome... and yesterday whole day I was trying it on chrome.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/249471-error-while-file-upload/#findComment-1281158 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.