• PHP/My SQL Upload help
    0 replies, posted
I have a website of my own and would be happyf you could help me build a view uploaded files page. I have a lot of stuff done so far. I'm a new at programming though, so I just want to know, how can I make it so if you click on a link, php chooses an id given to the flash based on the fllashes name, both of which are in a MySQL table. SWF's are given a random number as a file name when uploaded keep in mind. I want my system to be automatic so I don't have to upldate the page. Please respond as soon as you can. Tell me if you need any more info. Somebody please tell me how to make it when you click on a link to take you to the game with the id (rn). UPLOAD CODE: <?php // Configuration - Your Options $allowed_filetypes = array('.swf'); // These will be the types of file that will pass the validation. $max_filesize = 10485760; // Maximum filesize in BYTES (currently 5MB). $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // Find a random number that hasn't been used as a name yet, sequentials would take too long $valid = FALSE; while ($valid==FALSE) { $rn = rand(10,100000); if (!file_exists($upload_path . $rn . '.swf')) { $valid = TRUE; } } // Upload the file to your specified path. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $rn . '.swf')) echo 'Success! It can be seen <a href="' . $upload_path . $rn . '.swf' . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed :(. ?> <?php $flashname = $_POST["flashname"]; $email = $_POST["email"]; $firstname = $_POST["firstname"]; $description = $_POST["description"]; $largedes = $_POST["largedes"]; $audio = $_POST["audio"]; mysql_connect("localhost", "m552937_mikey", "$password") or die(mysql_error()); mysql_select_db("m552937_uploads") or die(mysql_error()); mysql_query("INSERT INTO info (flashname, email, firstname, description, largedes, audio, rn) VALUES('$flashname', '$email', '$firstname', '$description', '$largedes', '$audio', $rn) ") or die(mysql_error()); ?> [highlight](User was banned for this post ("Wrong Section" - Starpluck))[/highlight] [highlight](User was banned for this post ("Wrong Section" - Starpluck))[/highlight]
Sorry, you need to Log In to post a reply to this thread.