My problem recently arose when I tried to change save a picture to a location with a different name. eg. saving a picture called hello.jpg to a location called /sets/1/09092014-1.jpg
Here is my code:
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
$today = date("dmY");
$Title = $today."-".$x.".jpg";
$x ++;
$url = "/Sets/".$desired_dir."/".$Title;
$query = "INSERT INTO photo(name, url, album) VALUES('$Title', '$url', '$set')";
$result = mysql_query($query) OR DIE(mysql_error());
if($file_size > 10485760){
$errors[]='File size must be less than 2 MB';
}
if(empty($errors)==true){
if(is_dir("Sets/"."$desired_dir")==false){
mkdir("Sets/"."$desired_dir", 0700);
}
if(is_dir("Sets/"."$desired_dir/".$Title)==false){
rename ($file_tmp , $Title );
move_uploaded_file($file_tmp, "/Sets/$desired_dir/$file_tmp");
}else{
}
not including the DB stuff at the top.
I spent a while on this, and found that i may need to use the rename() method to rename the file before i save it, which I tried, but once again it didnt work.
When run, it adds the info to the database, creates the folder to be put in if not present, but then does not add the files.
Thanks, Waq