hey, I'm writing up this gallery where users may upload their own images. basically, they upload them to a folder and the data is also stored into a MySQL table.
I want to be able to either:
i) check if file exists and notify the user.
ii) add an autoincretment interger to the end of the filename if it exists.
right now, i am checking from the database if the filename exists. if it does, don't upload the file and notify user to rename their file.
but I have a problem. with certain files the error message is not returned but the error saying that the filetype is invalid does (even tho it is valid!). Quite confusing and VERY frustrating.
Here is the concerned code:
$SQL = "SELECT * FROM gallery WHERE username = '$username'";
$retid = @mysql_db_query(dbname, $SQL, $cid);
if (!$retid) { echo("<center><font face=arial color=red size=2><b>Data currently unavailable.</b></font></center>"); }
while ($row = @mysql_fetch_array($retid)) {
$userfile2 = $row["imagename"];
if($userfile_name != $userfile2){
$ext = strtolower(end(explode(".", $userfile_name)));
if($ext == "jpg" || $ext =="jpeg" || $ext == "gif"){
copy($userfile,$dir.$userfile_name);
$response = "$userfile_name uploaded.";
} else {
$response = "<font color='red'>File was of an invalid format ($ext). Only Jpegs and Gifs may be uploaded.</font><p>";
$insertdata = "no";
}
}else{
$response = "<font color='red'>That filename ($userfile_name) already exists on the server, please rename your file.</font><p>";
$insertdata = "no";
}
}
}
I would really appriciate any help or suggestions on this! Thanks a lot 🆒