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? Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/ Share on other sites More sharing options...
papaface Posted April 6, 2007 Share Posted April 6, 2007 file_exists Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223132 Share on other sites More sharing options...
MadTechie Posted April 6, 2007 Share Posted April 6, 2007 what part you stuck on ? Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223158 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? Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223197 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 =) Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223198 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? Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223237 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 Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223240 Share on other sites More sharing options...
MadTechie Posted April 7, 2007 Share Posted April 7, 2007 rename("1.txt", "2.txt"); Link to comment https://forums.phpfreaks.com/topic/45936-check-if-file-exists-rename-etcc/#findComment-223241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.