pouncer Posted April 6, 2007 Share Posted April 6, 2007 I've got this code here which uploads a profile image file.. if (isset($_POST['Submit'])) { $_accepted_extensions = array('.jpg', '.bmp', '.gif', '.JPG', '.BMP', '.GIF'); $tmp = pathinfo($_FILES['imageupload']['name']); if (!in_array('.' . $tmp['extension'], $_accepted_extensions)) { echo "The image you attempted to upload is of the wrong file type."; } else { $target_path = "../profile_images/"; $nm = basename($_FILES['imageupload']['name']); $target_path = $target_path . $nm; if (move_uploaded_file($_FILES['imageupload']['tmp_name'], $target_path)) { echo "The file ". $nm . " has been uploaded to your profile."; $user_id = $_SESSION['UserID']; $Image_URL = "thumbnail.php?im=" . "profile_images/" . $nm; $profile = mysql_query("UPDATE user_profile SET Image_URL = '$Image_URL' WHERE user_id = '$user_id' ") or die (mysql_error()); } else echo "There was an error uploading the image, please try again."; } } I want to change it though to work with: if the file already exists on the ftp, rename the filename (possible adding a random 6 digit number to end of filename?) and upload it. also to store this new filename in the sql table . can anyone help me? Quote Link to comment Share on other sites More sharing options...
papaface Posted April 6, 2007 Share Posted April 6, 2007 file_exists Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 6, 2007 Share Posted April 6, 2007 what part you stuck on ? Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2007 Author Share Posted April 6, 2007 thanks. where do i put the file_exists part? and also, if the file does exist how do i rename it the way i put in my 1st post? any help anyone? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 6, 2007 Share Posted April 6, 2007 i'm not a really advanced PHP programmer but from what I know you can add the file_exists() like this <? if (file_exists(filename)) { commands } elseif (!file_exists(filename)) { commands } ?> on the rename part I have no clue.. hope it helped you a little bit further to success =) Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 7, 2007 Author Share Posted April 7, 2007 can someone please help on the rename part? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 7, 2007 Share Posted April 7, 2007 http://no.php.net/manual/en/function.rename.php Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 7, 2007 Share Posted April 7, 2007 rename("1.txt", "2.txt"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.