So I want to add a random number and a _ on to the begging of the original file name before it pushes to the DB and the assigned folder.
I've been looking around the internet all evening and cant find my solution
Heres my code
This works perfectly to upload my file to the db and folder but if you take a photo on an ios device the file is always named image.jpg
$images_arr = array();
$target_dir = "uploads/";
$target = $target_dir.$_FILES['photo']['name'];
//$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$userId=$_POST['userId'];
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
// Connects to your Database
mysql_connect("", "", "") or die(mysql_error()) ;
mysql_select_db("") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO portal_phocagallery (user_id,title,alias,filename,description)
VALUES ('$userId', '$name', '$bandMember', '$pic', '$about')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES ['photo']['tmp_name'], $target)){
//Tells you if its all ok
echo "The file ". $target_dir.$_FILES['photo']['name']. " has been uploaded, and your information has been added to the directory";
$images_arr[] = $target;
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
function errorMessage($str) {
return '<div style="width:50%; margin:0 auto; border:2px solid #F00;padding:2px; color:#000; margin-top:10px; text-align:center;">' . $str . '</div>';
}
function successMessage($str) {
return '<div style="width:50%; margin:0 auto; border:2px solid #06C;padding:2px; color:#000; margin-top:10px; text-align:center;">' . $str . '</div>';
}
Thanks is advance!
I got it working perfectly by changing the top few lines of code to this
$images_arr = array();
//This is the directory where images will be saved
$target_dir = "uploads/";
$file = rand().'_'.$_FILES['photo']['name'];
$target = $target_dir.$file;
//$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$userId=$_POST['userId'];
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=$file;
$about=$_POST['aboutMember'];