doforumda Posted November 13, 2009 Share Posted November 13, 2009 hi i am having problem in uploading file can anyone tell me what am i doing wring in the following script <form enctype="multipart/form-data" method="post" action="uploadimages.php"> <input type="hidden" name="MAX_FILE_SIZE" value="20000"> <div> <label class="upload">Choose File:</label> <input name="uploadedfile" type="file"> </div> <div> <label class="upload">Name:</label> <input type="text" name="name" id="textfield" /> </div> <div> <label class="upload">Cover:</label> <input type="text" name="cover" id="textfield2" /> </div> <div> <label class="upload">Description:</label> <textarea name="desc" id="textarea" cols="45" rows="5"></textarea> </div> <div class="actions"> <input class="actions" type="submit" name="submit" id="button" value="Upload" /> </div> </form> <?php require("connect.php"); if(@$_POST['submit']) { $name = $_POST['name']; $cover = $_POST['cover']; $desc = $_POST['desc']; $file = $_FILES['uploadedfile']; $target_path = "projectimages/"; echo $name."<br>"; echo $cover."<br>"; echo $desc."<br>"; $target_path_name = $target_path . basename($file['name']); echo $target_path_name."<br>"; if(move_uploaded_file($file['tmp_name'], $target_path_name)) { echo "<p><b>The file ".$target_path_name." has been uploaded</b></p>"; $insert = "INSERT INTO projectimages (name,description,cover) values ('".$name."','".$desc."','".$cover."')"; echo $insert; $result = mysql_query($insert); } else die("There was an error uploading the file, please try again!"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/ Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 if(@$_POST['submit']) if($_POST['submit']) Read through the following. http://www.tizag.com/phpT/fileupload.php Also code that processes data should be prior to any html. This is always best practice i.e. <?php // process post data if($_POST['submit']) { // validate } // html ?> <html> <body> <form> blah, blah, blah </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956811 Share on other sites More sharing options...
PFMaBiSmAd Posted November 13, 2009 Share Posted November 13, 2009 can anyone tell me what am i doing wrong Not until you tell us what symptoms or errors you get. There are at least a dozen different things that could prevent the code you posted from working on your server and with the input you supplied it and unless you state what it does when you try it, no one can tell you which of the possible things is preventing it from working. BTW - The code worked for me. The selected file was uploaded and the INSERT query was formed the way the code intends. Edit: And I have to ask, are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini to get php to help you by displaying all the errors that it detects? You will save a ton of time. Stop and start your web server to get any changes made to php.ini to take effect and confirm that the settings are actually changed using a phpinfo() statement in case the php.ini that you are changing is not the one that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956813 Share on other sites More sharing options...
doforumda Posted November 13, 2009 Author Share Posted November 13, 2009 can anyone tell me what am i doing wrong Not until you tell us what symptoms or errors you get. There are at least a dozen different things that could prevent the code you posted from working on your server and with the input you supplied it and unless you state what it does when you try it, no one can tell you which of the possible things is preventing it from working. BTW - The code worked for me. The selected file was uploaded and the INSERT query was formed the way the code intends. the if condition does not get true. it displays else statement i.e, "There was an error uploading the file, please try again!" Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956815 Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 How big is this file? This line will not do anything in your logic! <input type="hidden" name="MAX_FILE_SIZE" value="20000"> Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956816 Share on other sites More sharing options...
doforumda Posted November 13, 2009 Author Share Posted November 13, 2009 How big is this file? it is 79KB Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956817 Share on other sites More sharing options...
doforumda Posted November 13, 2009 Author Share Posted November 13, 2009 thanks it is working now file size was the problem. Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956818 Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 How big is this file? it is 79KB Check the filesize using if($_FILES['uploadedfile']['size'] > 4000) { // file is too large } Your error handling is too vague. It is not telling you what is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/#findComment-956819 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.