svgmx5 Posted December 16, 2010 Share Posted December 16, 2010 I'm working on this application that allows the user to submit up to 10 files into the server and database. The files can be either images or video files.. What i'm looking for is for people in this forum to see if they can look it over and see if they find anything that can be fixed that might screw things up. Also I have yet to test it, i know i should test first and them come here for help, but i currently don't have a server to test it until tomorrow..so all i need is to see if you guys can look it over and let me know if i'm doing something wrong if there would be a better way to do it Thankyou <?php if(isset($_POST['submit'])){ $dir = 'images/content'; $date_sub = date('m/d/y'); $time_sub = date('h:i A'); $ip = $_SERVER['REMOTE_ADDR']; foreach($_FILES['file']['name'] as $key => $file){ $type = mysql_real_escape_string($_POST['type']); $fileupload = $dir.$file; move_uploaded_file($_FILES['file']['tmp_name'][$key], $fileupload); $add_files = mysql_query("INSERT INTO content (contentURL, contentType, profileID, date_submitted, time_submitted, ip_log) VALUES('$file', '$type', '$profileID', '$time_sub', '$date_sub', 'ip')") or die(mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221917-can-someone-look-over-this-script/ Share on other sites More sharing options...
mikecampbell Posted December 16, 2010 Share Posted December 16, 2010 Looks fine, but instead of a field for the date and time as strings, you should use a single integer field. Insert into this field the unix timestamp as returned by time(). This will store both the time and date in one field, and allow you to sort by date if necessary. When displaying the timestamp, use date() to format it. Quote Link to comment https://forums.phpfreaks.com/topic/221917-can-someone-look-over-this-script/#findComment-1148385 Share on other sites More sharing options...
QuickOldCar Posted December 16, 2010 Share Posted December 16, 2010 If don't want any same named files being overwritten, can rename them and place a timestamp at the beginning of the filename. You can integrate the idea as you see fit to your code $timestamp = time(); $file_name = $timestamp.$_FILES['file']['name']; $source = $_FILES["file"]["tmp_name"][$key] ; $filename1 = $_FILES["file"]["name"][$key]; $filename = strtolower($filename1); $filename = "$timestamp$filename"; Quote Link to comment https://forums.phpfreaks.com/topic/221917-can-someone-look-over-this-script/#findComment-1148405 Share on other sites More sharing options...
svgmx5 Posted December 16, 2010 Author Share Posted December 16, 2010 Thank you guys for the replies I think i'll do that, bc i don't want any files to be overwritten Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/221917-can-someone-look-over-this-script/#findComment-1148419 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.