ChrisPHP Posted January 5, 2013 Share Posted January 5, 2013 Hello everyone, Hope you're doing all fine I just wanted to ask about something that's happening to me recently.. Whenever I change the name of a file, it automatically adds up Array in the beginning of the name. I just wanted to know if there's a way to prevent it I'm using $target = $target . basename($_FILES['AImage']. $an .'.jpg'); where AImage is the name of the field in mysql and $an is the name that I wanted to put Thanks in advance. Best regards, Chris Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/ Share on other sites More sharing options...
jazzman1 Posted January 6, 2013 Share Posted January 6, 2013 Try, $target = basename($_FILES['AImage']; $value = array_shift($target); $target = $target . $value . $an .'.jpg'); Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/#findComment-1403501 Share on other sites More sharing options...
ChrisPHP Posted January 6, 2013 Author Share Posted January 6, 2013 It did solve my problem thanks a million Just for comprehension.. what does array_shift() actually do? Thanks a lot again Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/#findComment-1403503 Share on other sites More sharing options...
Andy123 Posted January 6, 2013 Share Posted January 6, 2013 Just for comprehension.. what does array_shift() actually do? From the manual: array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. So if you do the following: $companies = array('Microsoft', 'Google', 'Apple'); $removed_company = array_shift($companies); Then $companies will only contain "Google" and "Apple", and $removed_company will contain "Microsoft". Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/#findComment-1403504 Share on other sites More sharing options...
ChrisPHP Posted January 6, 2013 Author Share Posted January 6, 2013 Thanks a lot Andy, I really appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/#findComment-1403507 Share on other sites More sharing options...
Andy123 Posted January 6, 2013 Share Posted January 6, 2013 You are very welcome. Quote Link to comment https://forums.phpfreaks.com/topic/272741-changing-the-name-of-file-uploaded-adds-up-array-to-the-name/#findComment-1403510 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.