Jump to content

Recommended Posts

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());
								}
							}
						?>

 

Link to comment
https://forums.phpfreaks.com/topic/221917-can-someone-look-over-this-script/
Share on other sites

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.

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";

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.