CiszLaserna Posted February 9, 2013 Share Posted February 9, 2013 (edited) here is my upload_file.php <?php $allowedExts = array("jpg", "jpeg", "gif", "png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ($_FILES["file"]["size"] < 20000) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')"; } } } else { echo "Invalid file"; } ?> and here is my insert code for the result because a wanted to try if i can download the file i upload from the db itself <?php $con=mysql_connect("localhost","root",""); mysql_select_db("report"); $sql="INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')"; $sql_res = mysql_query($sql); header("Location: report.php?ok=1"); mysql_close($con); ?> form code html <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="Submit"> </form> im kinda new at php Edited February 9, 2013 by CiszLaserna Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/ Share on other sites More sharing options...
wigwambam Posted February 9, 2013 Share Posted February 9, 2013 It could be anything from a coding error to incorrect folder permissions - do you get an error message? Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411372 Share on other sites More sharing options...
timothyarden Posted February 10, 2013 Share Posted February 10, 2013 To set error reporting to everything add this to the top of your code error_reporting(E_ALL); ini_set('display_errors',1); Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411436 Share on other sites More sharing options...
timothyarden Posted February 10, 2013 Share Posted February 10, 2013 Also what is this doing in the else { } in the first lot of code? INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')"; You already have that in the mysql_query in the second file Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411437 Share on other sites More sharing options...
CiszLaserna Posted February 10, 2013 Author Share Posted February 10, 2013 now my problem is i want the file to print in the result as a downloadable once i upload it usng the php file upload code. Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411462 Share on other sites More sharing options...
timothyarden Posted February 10, 2013 Share Posted February 10, 2013 Perhaps put it into a zip file either before you upload it or use php to put it into a zip file and then echo '<a href="'.$filedir.$filename.'"/>'.$filename.'</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411465 Share on other sites More sharing options...
Zane Posted February 10, 2013 Share Posted February 10, 2013 (edited) Cisz, you have failed to even mention the exact problem you are having. You pretty much just regurgitated your code out to us and said "It doesn't work." As you can see by the number of replies you surprisingly have already, this community wants to help you, but they cannot do so effectively if you do not ask your question effectively. Are you positive that your file uploaded correctly? If you are not sure, then check through FTP or whatever means you use to view your files.... if it is there, then you're problem may be that you are giving the wrong path. We need to know things like, your directory structure and whether or not the upload actually works....etcetera... details. Edited February 10, 2013 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/#findComment-1411467 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.