chris_rulez001 Posted July 7, 2007 Share Posted July 7, 2007 hi i have made a file upload script and its not working, its saying im firefox that the connection has been reset when it hasn't. my code: <?php $id = $_POST['id']; $username = $_POST['username']; $allowed_ext = "jpg, gif, png, pdf, bmp, swf, mp3, wma"; if( strpos($_FILES["file"]["type"], $allowed_ext) == true && $_FILES["file"]["size"] < 50000 ) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "<h4>Upload Successful!</h4><br/>"; echo "<strong>Upload:</strong> " . $_FILES["file"]["name"] . "<br /><br />"; echo "<strong>Type:</strong> " . $_FILES["file"]["type"] . "<br /><br />"; echo "<strong>Size:</strong> " . ($_FILES["file"]["size"] / 1024) . " Kb<br /><br />"; echo "<strong>Temp file:</strong> " . $_FILES["file"]["tmp_name"] . "<br /><br />"; if (file_exists("memberuploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "memberuploads/" . $_FILES["file"]["name"]); echo "<strong>Stored in:</strong> " . "http://*********.awardspace.com/memberuploads/" . $_FILES["file"]["name"]; echo "<br/><br/><strong>ALL</strong> inappropriate images, movies, music <strong>WILL</strong> be deleted!"; echo "<br/><br/>Click <a href='index.php'>here</a> to return to the homepage."; $filename = $_FILES["file"]["name"]; mysql_connect("fdb1.awardspace.com", "************", "********") or die ('Connection to database failed: ' . mysql_error()); mysql_select_db("************"); $today = date("D M d Y"); $filetype = $_FILES["file"]["type"]; $filesize = $_FILES["file"]["size"]; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO tracking(id, username, date, ipaddress, filename, filetype, filesize) VALUES ('$id', '$username', '$today', '$ip', '$filename', '$filetype', '$filesize')"); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 8, 2007 Author Share Posted July 8, 2007 help someone? Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted July 15, 2007 Author Share Posted July 15, 2007 bump, can someone help me please? Quote Link to comment Share on other sites More sharing options...
lur Posted July 15, 2007 Share Posted July 15, 2007 This will never work, the only way for strpos() to find a match is if $_FILES['file']['type'] is a string equal to the entire contents of $allowed_ext, in which case strpos() will return int(0) which will evaluate to FALSE. <?php $allowed_ext = "jpg, gif, png, pdf, bmp, swf, mp3, wma"; if (strpos($_FILES["file"]["type"], $allowed_ext) == true) { } ?> This would work: <?php $allowed_ext = "jpg, gif, png, pdf, bmp, swf, mp3, wma"; $allowed_ext = preg_split('/\s*,\s*/', $allowed_ext, -1, PREG_SPLIT_NO_EMPTY); if (in_array($_FILES['file']['type'], $allowed_ext)) { } ?> Quote Link to comment 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.