Image uploader
Posted: Sat Feb 01, 2003 11:15 pm
I had this code:
I edited it so that from a form on a page you can upload an image to a folder and add stuff like a title and the users email etc..
But i want it so the the user can choose from 5 diffrent folders to upload the image to (from a drop down menu on the forum)
I have used the base code and that code you see above along with some other stuff to make it all work the only problem is as you can see if the base code it sets the name to fubar0 and if there is fubar0 to make it to 1 then 2 however when i try to change my code to add the drop down menu results eg ../../darkside/Upload/fubar, ../../wr4ck/Upload/fubar. (this being $god)
the right hand code works
But the left hand doesnt
So when i run the post i end up finding the image in ../../darkside folder name fubar1Upload, fubar2Upload.
Ok then there is alot of code up and round there but its the only way this is going to make any sence. Any help wouldnt go a miss.
Code: Select all
<?php
function getNextSerial($prefix, $path)
{
$max = -1;
$dir = opendir($path);
while($fname = readdir($dir))
{
if(strpos($fname, $prefix) === (int)0)
$max = max($max, (int)substr($fname, strlen($prefix)));
}
return ++$max;
}
$postfix = strrchr($_FILESї'filename']ї'name'], '.');
$fname = '../../darkside/Upload/fubar' . getNextSerial('fubar', '../../darkside/Upload/fubar' ).$postfix;
if(!(copy($_FILESї'userfile']ї'tmp_name'], "$fname" . ".jpg")));
$post_data = "posts.php";
$data = fopen($post_data, "a");
fwrite($data, "$fname");
fclose($data);
?>But i want it so the the user can choose from 5 diffrent folders to upload the image to (from a drop down menu on the forum)
Code: Select all
$postfix = strrchr($_FILESї'filename']ї'name'], '.');
$fname = ("$god").('fubar') . getNextSerial('fubar',"$god".$postfix);the right hand code works
Code: Select all
$postfix = strrchr($_FILESї'filename']ї'name'], '.');
$fname = ("$god").('fubar')Code: Select all
getNextSerial('fubar',"$god".$postfix);Ok then there is alot of code up and round there but its the only way this is going to make any sence. Any help wouldnt go a miss.