matthew9090 Posted March 31, 2011 Share Posted March 31, 2011 move_uploaded_file($_POST['file']['tmp_name'], "upload/"); doesn't work and if i echo the tmp name it comes up with the first letter of the uploaded file. please help! Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/ Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 Please show your entire code Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195085 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 <?php error_reporting(E_ALL); $name = $_POST['name']; $file = $_POST['file']; $moved = move_uploaded_file($_POST['file']['tmp_name'], "upload/"); if ($moved) { echo "moved!"; } else { echo "did not move!"; } echo $name . "<br />" . $file . "<p>"; if (strlen($name)>10) { echo "name too long"; } else { //private stuff Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195086 Share on other sites More sharing options...
betterphp Posted March 31, 2011 Share Posted March 31, 2011 the second parameter should be the full location of the new file, including its name. Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195088 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 that doesn't work it comes up with 'did not move' Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195090 Share on other sites More sharing options...
PFMaBiSmAd Posted March 31, 2011 Share Posted March 31, 2011 Uploaded file information is in $_FILES, not $_POST and given that your $_POST array has something in it suggests that your form doesn't have the correct enctype= parameter in it. Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195092 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 $_FILES doesnt work either Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195095 Share on other sites More sharing options...
betterphp Posted March 31, 2011 Share Posted March 31, 2011 $_FILES doesnt work either post the full code you are using. Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195097 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 i am making a game upload site and here is my full code undedited: <html> <head> <title>Quickplay</title> <link rel="stylesheet" type="text/css" href="style/main.css" /> <link rel="stylesheet" href="style/menu_style.css" type="text/css" /> </head> <body> <?php include('includes/header.php'); ?> <div id="content"> <?php error_reporting(E_ALL); $name = $_POST['name']; $file = $_FILES['file']; echo "<p>" . $_FILES['file']['tmp_name']; $moved = move_uploaded_file($_FILES['file']['tmp_name'], "games/flash/$file"); if ($moved) { echo "<p>moved!"; } else { echo "<p>did not move!"; } echo $name . "<p><br />" . $file . "<p>"; if (strlen($name)>10) { echo "name too long"; } else { include('includes/connect.php'); $random = rand(1000000000, 2000000000); $start = "<a href ="; $end = ">$name</a>"; $link = "games/" . $random . ".php"; mysql_query("INSERT INTO games (gamename, gamefile, link) VALUES('$name', '$file', '$link') "); $sqlfile = "SELECT * FROM games WHERE gamefile='$file'"; $file2 = mysql_query($sqlfile); $file3 = @mysql_fetch_assoc($file2); $file4 = $file3['gamefile']; $fp = fopen("$link", 'w') or die('error'); $html = " <html> <head> <title>Quickplay - $name</title> <link rel='stylesheet' type='text/css' href='../style/main.css' /> <link rel='stylesheet' href='../style/menu_style.css' type='text/css' /> </head> <body> <div class='title'><img src = '../images/logo.png' width='275' height='100' align='top'></img></div> <ul id='menu'> <li><a href='../index.php' target='_self'>Home</a></li> <li><a href='../games.php' target='_self'>Games</a></li> <li><a href='../forum.php' target='_self'>Forum</a></li> <li><a href='../upload.php' target='_self'>Upload Game</a></li> <li><form><a>Search games</a><input type='text' width='10' id='search' /></form></li> </ul> <div id='content'> <h2>$name</h2> <object width='432' height='330' title='game'> <param name='movie' value='games/flash/$file4' /> <param name='quality' value='high' /> <embed src='games/flash/$file4' type='application/x-shockwave-flash' width='432' height='330'></embed> </object> </div> <?php include('../includes/footer.php'); ?> </body> </html> "; fwrite($fp, "$html"); fclose($fp); mysql_close($con); echo "<p>Success!</p><p><a href='index.php'>Go back</a>"; } ?> </div> <?php include('includes/footer.php'); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195101 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2011 Share Posted March 31, 2011 Please post the form. Ken Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195103 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 <form method="post" action="game_upload.php"> Name of the game: <input type="test" maxlength="10" name="name" /><br /> Game file: <input type="file" name="file" id="file" /><br /> <input type="submit" value="Submit" name="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195128 Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 to upload files, you need this is your form - enctype="multipart/form-data" - see - http://www.tizag.com/phpT/fileupload.php Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195138 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks guys that really helped but 1 more thing is that i downloaded a flash game then it came with a html page set up so i clicked it and the game played fine but when i put the flash file into my website through the form it comes up with the exact same html code apart from the directory (which should be right) and comes up as a white box. downloaded <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="640" height="480"> <param name="movie" value="firstflight.swf"> <param name="quality" value="high"> <embed src="firstflight.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="640" height="480"> </embed> </object> mine <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='640' height='480'> <param name='movie' value='firstflight.swf'> <param name='quality' value='high'> <embed src='games/flash/firstflight.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='640' height='480'> </embed> </object> Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195152 Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 The simplest problems when displaying images/videos/music is that the path is incorrect, so 1) verify you have the correct path; 2) verify that the swf is, infact , in the proper folder Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195155 Share on other sites More sharing options...
matthew9090 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks people! it works now, it was the path. Link to comment https://forums.phpfreaks.com/topic/232311-move_uploaded_file-not-working/#findComment-1195164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.