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 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'); 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 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". 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 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. 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
Archived
This topic is now archived and is closed to further replies.