chris_rulez001 Posted June 24, 2008 Share Posted June 24, 2008 hi whats wrong with this php file upload code: <?php $action = $_GET['action']; switch($action) { default: if(!isset($_SESSION['username']) == false) { echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"?action=upload\"> <input type=\"file\" name=\"fileToUpload\" /><br /> <input type=\"submit\" value=\"Upload File\" /> </form><br/><br/>Maximum Video Size: 3 MB (3,000 KB)"; } else { echo "<table width=\"400\" border=\"1\"> <tr> <td align=\"center\">Access Denied</td> </tr> <tr> <td align=\"center\">You are not allowed to view this page.</td> </tr> </table>"; } break; case upload: if (($_FILES["fileToUpload"]["type"] == "movie/mpeg4") || ($_FILES["fileToUpload"]["type"] == "movie/3gpp") && ($_FILES["fileToUpload"]["size"] < 3000)) { move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "uservideos/" . $_FILES["fileToUpload"]["name"]); echo "<table border=\"1\">"; echo "<tr><td>Client Filename: </td> <td>" . $_FILES["fileToUpload"]["name"] . "</td></tr>"; echo "<tr><td>File Type: </td> <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>"; echo "<tr><td>File Size: </td> <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>"; echo "<tr><td>Name of Temporary File: </td> <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>"; echo "</table>"; echo "File Successfully Uploaded"; } else { echo "Files must be either 3PG or MP4 and less than 3,000 KB (3 MB)<br/><br/><a href=\"javascript:history.go(-1)\">Go Back</a>"; } break; } ?> Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 check that your folder permissions are set to write. Though I'd highly suggest resetting them to 711 or lower after the upload. If you don't know what I mean by that, use an ftp client to connect to your site, find the "uservideos" folder, right click and view properties. You should see some sort of 3 digit value somewhere(possibly starting with a 6 or 7). Tell us what it sas Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 24, 2008 Author Share Posted June 24, 2008 im running my site on localhost and i cant ftp localhost Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 Ok well obviously you don't know what I'm talking about... Download a program FileZilla... then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 24, 2008 Share Posted June 24, 2008 How about you provide an error message with your code. Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 24, 2008 Author Share Posted June 24, 2008 How about you provide an error message with your code. Files must be either 3PG or MP4 and less than 3,000 KB (3 MB) thats my error message Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 lol thats the error message you typed yourself. The way you have it setup is to display the error if the uploaded image isn't transferred successfully. It could be a ton of different things. I'm telling you, it's probably bc your folder's permissions aren't set to be written into Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 24, 2008 Author Share Posted June 24, 2008 Ok well obviously you don't know what I'm talking about... Download a program FileZilla... then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see EDIT: nevermind, im just finding the 3 digit value Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 24, 2008 Author Share Posted June 24, 2008 Ok well obviously you don't know what I'm talking about... Download a program FileZilla... then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see EDIT: nevermind, im just finding the 3 digit value the 3 digit value is 755 Quote Link to comment Share on other sites More sharing options...
chris_rulez001 Posted June 24, 2008 Author Share Posted June 24, 2008 i have found something out. this code works fine uploads all files but i would like to restrict all files exept 3gp and mp4 files: <?php $action = $_GET['action']; switch($action) { default: if(!isset($_SESSION['username']) == false) { echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"?action=upload\"> <input type=\"file\" name=\"fileToUpload\" /><br /> <input type=\"submit\" value=\"Upload File\" /> </form><br/><br/>Maximum Video Size: 3 MB (3,000 KB)"; } else { echo "<table width=\"400\" border=\"1\"> <tr> <td align=\"center\">Access Denied</td> </tr> <tr> <td align=\"center\">You are not allowed to view this page.</td> </tr> </table>"; } break; case upload: if (($_FILES["fileToUpload"]["type"] == "video/mpeg4") || ($_FILES["fileToUpload"]["type"] == "video/3gpp") && ($_FILES["fileToUpload"]["size"] < 3000)) { echo "Files must be either 3PG or MP4 and less than 3,000 KB (3 MB)<br/><br/><a href=\"javascript:history.go(-1)\">Go Back</a>"; } else { move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "uservideos/" . $_FILES["fileToUpload"]["name"]); echo "<table border=\"1\">"; echo "<tr><td>Client Filename: </td> <td>" . $_FILES["fileToUpload"]["name"] . "</td></tr>"; echo "<tr><td>File Type: </td> <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>"; echo "<tr><td>File Size: </td> <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>"; echo "<tr><td>Name of Temporary File: </td> <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>"; echo "</table>"; echo "<br/>File Successfully Uploaded.<br/><br/><a href=\"upload.php\">Upload More Videos</a> Or <a href=\"index.php\">Return To Homepage</a>"; } break; } ?> Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 then you'd get the posted item into a variable.. say $file $temp = explode(".", $file); $size = sizeof($temp); $type = $temp[$size-1]; if($type == "3gp" || $type == "mp4") { error message; } else { upload file; } 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.