Nookzor wrote:
Now , is there any way i can tweak this script so i can upload multiple files with filename change?
Yes
Nookzor wrote:
Also , let,s say that i upload 4 files at a time which are associated with an entry in the sql database.Each entry has an unique id with auto_increment attribute.
Is there any way i can make the script create a different folder for each entry where to upload the picture files ? ( E.G. images/231/1.jpg , 2.jpg , 3.jpg , 4.jpg | images /232/1.jpg etc where 231 and 232 are the unique id's from the sql database ) Or do i have to name the files by the id and place them all in the same directory ( E.G. images/231-1.jpg , 231-2 ... 232-1.jpg and so on ).
Yes
You will want to use MySQL's LAST_INSERT_ID() to get the last ID inserted and [man]mkdir[/man] to create the directories based on LAST_INSERT_ID().
$HTTP* are depreciated. Use $POST, $GET, $SESSION, $COOKIE, $REQUEST, etc...
i.e. UNTESTED
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<form enctype="multipart/form-data" action="test.php" method="POST">
<p>Pic 1</p>
<input name="file[]" type="file" size="50" />
<input name="file[]" type="file" size="50" />
<input name="file[]" type="file" size="50" />
<input name="file[]" type="file" size="50" />
<input name="file[]" type="file" size="50" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
$query = mysql_query("SELECT LAST_INSERT_ID() FROM table");
$result = mysql_result($query, 0);
$images = $_FILES['myfiles'];
$totalImages = count($images['name']);
$dir = dirname(__FILE__).'/images/';
for($i=0;$i<$totalImages;$i++){
if(!is_dir($dir.$result))
mkdir($dir.$result);
move_uploaded_file($images['tmp_name'][$i], $dir.$result.'/'.$images['name'][$i]);
}
That is pretty basic and needs error handling, but it should show you the most of the functions you will need to use.