adam291086 Posted January 14, 2008 Share Posted January 14, 2008 Good. That now means something has been upload. Look in your root and check to see if the file was moved into their. Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438868 Share on other sites More sharing options...
spikypunker Posted January 14, 2008 Author Share Posted January 14, 2008 Ah HA! Something HAS been uploaded! The website is in root/public_html but the file has been put in root/ SO why the hell wasnt my orignal form doing the same? AND how do i get it to save the file in my uploads folder? Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438873 Share on other sites More sharing options...
adam291086 Posted January 14, 2008 Share Posted January 14, 2008 The path needs to be absolute i think. Not 100%. The file is going to root because of $path = dirname(__FILE__); so change it to go into the correct directory $path = dirname(__FILE__)."/uploads/"; I think thats what you want. Assuming uploads is a folder in the root directory Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438879 Share on other sites More sharing options...
spikypunker Posted January 14, 2008 Author Share Posted January 14, 2008 Sweet i added: ."public_html/uploads/" to the end of that and it's uploading to the right directory. Ok i'm gonna try and add my php ITEM ID script into the new page and see if i can get that working, will come back if that doesn't work :-\ Cheers for help so far dude! peace Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438888 Share on other sites More sharing options...
spikypunker Posted January 14, 2008 Author Share Posted January 14, 2008 Excellent, it now works great! If anyone wants to do this aswell and is new to PHP like me, this uploads an image and saves it with a filename of the ID of a selected news item from the database. Ie You select News story 3, then choose a file. Then it uploads it and saves it as "3.gif" Now i just need to add some validation so it only lets GIFs be uploaded etc, and it's finished!! Thanks so much for your help adam. <html> <body><form action="uploader.php" method="post" enctype="multipart/form-data"> <? mysql_connect("db1", "stanga_1", "pencil"); @mysql_select_db("stanga_1") or die ("unable to connect"); $query = "SELECT * FROM news ORDER BY date desc"; $result = mysql_query($query); $num = mysql_num_rows($result); mysql_close(); $i = 0; while ($i < $num) { $newsno = mysql_result($result,$i,"newsno"); $date = mysql_result($result,$i,"date"); $head = mysql_result($result,$i,"head"); $body = mysql_result($result,$i,"body"); ?> <input name="item" type="radio" id="item" value="<? echo $newsno; ?>"> <? echo " <span class='style2'>$head</span><br>"; $i++; } ?> <Br> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /><br> <input type="submit" name="submit" value="Submit" /> </form></body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Delete</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style> </head> <body> <span class="style1"> <?php $id = $_POST['item']; $path = dirname(__FILE__)."public_html/uploads/"; $path = dirname(__FILE__)."/uploads/"; $destination= $path; $id = $id . ".gif"; if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $id); echo "<meta http-equiv=\"refresh\" content=\"0;URL=in.html\">"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438923 Share on other sites More sharing options...
adam291086 Posted January 14, 2008 Share Posted January 14, 2008 Its ok, here is an example of how i got the file type $file_type= $_FILES["file"]["name"]; $extention = strtolower(end(explode('.', $file_type))); if ($extention != 'gif') { unlink($destination .$file_type); echo "Invalid file. "; } Quote Link to comment https://forums.phpfreaks.com/topic/85499-solved-php-file-uploader/page/2/#findComment-438925 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.