Jump to content


Photo

Changing the name of file uploaded adds up Array to the name


  • Please log in to reply
5 replies to this topic

#1 ChrisPHP

ChrisPHP

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLebanon

Posted 05 January 2013 - 06:49 PM

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
Best regards,
Chris

#2 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,631 posts
  • LocationMississauga, Canada

Posted 05 January 2013 - 07:18 PM

Try,
$target = basename($_FILES['AImage'];
$value = array_shift($target);
$target = $target . $value . $an .'.jpg');


#3 ChrisPHP

ChrisPHP

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLebanon

Posted 05 January 2013 - 07:46 PM

It did solve my problem thanks a million :)
Just for comprehension.. what does array_shift() actually do?
Thanks a lot again :)
Best regards,
Chris

#4 Andy123

Andy123

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationDenmark

Posted 05 January 2013 - 07:55 PM

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".
Blogging about PHP and other programming related subjects at CodingExplained.com.

#5 ChrisPHP

ChrisPHP

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLebanon

Posted 05 January 2013 - 08:23 PM

Thanks a lot Andy, I really appreciate your help :)
Best regards,
Chris

#6 Andy123

Andy123

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationDenmark

Posted 05 January 2013 - 08:43 PM

You are very welcome. :)
Blogging about PHP and other programming related subjects at CodingExplained.com.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com