Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:54:24+00:00 2026-06-07T08:54:24+00:00

I am running a PHP script to upload files from a HTML form, rename

  • 0

I am running a PHP script to upload files from a HTML form, rename them and place them on my server. It is uploading and renaming, however every file name now starts with the word “Array”
ie: ArrayTest Document v1.0.pdf
I am fairly confident it isn’t my $newfn variable as I display that in a table and it doesnt show up.

//This gets all the other information from the form
$name=$_POST['docname'];
$version=$_POST['docver'];
$date=$_POST['docdate'];
$type=$_POST['doctype'];
$author=$_POST['docauth'];
$file=$_FILES['uploaded']['name'];

//target directory is assigned
$target = $directory;
$target = $target . basename($file) ;

//grab file extension
$filetypes = array(
'image/png' => '.png',
'image/gif' => '.gif',
'image/jpeg' => '.jpg',
'image/bmp' => '.bmp',
'application/pdf' => '.pdf');
$ext = $filetypes[$_FILES['uploaded']['type']];

//generate new filename variable "name v??.xxx"
$newfn = $name . ' ' . 'v' . $version . $ext;

//Check to see if file exists
if (file_exists($directory . $file))
{
echo $_FILES["uploaded"]["name"] . " already exists. ";
}
else
{
//if its a new file, change name and upload
    if (move_uploaded_file($_FILES["uploaded"]["tmp_name"],
        $directory . $_FILES["uploaded"] . $newfn))
        {
        echo "The file ". basename($file). " has been uploaded";
        }
        else
        {
        echo "Sorry, there was a problem uploading your file.";
        }
}

I feel like it’s related to my $FILES['uploaded'] section in the move_uploaded_file command. I’ve tried googling but as soon as I mention “Array” my google results are nothing remotely the same.

Ok so thanks to below I solved it. For anyone in the future I removed the entire $_FILES array so the code reads as

//if its a new file, change name and upload
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"],
    $directory . $newfn))

Everything now uploads with the correct name structure. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:54:26+00:00Added an answer on June 7, 2026 at 8:54 am

    Should be

    move_uploaded_file($_FILES["uploaded"]["tmp_name"],$directory . $_FILES["uploaded"]["name"] . $newfn)
    

    You forgot to include [“name”] after $_FILES[“uploaded”]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a php script from the command line against SQL server 2005 using
I have a PHP script running on my LAMP server that requires certain files
i have a php script which should upload files upto 1GB to server. i
I am running a php script from the console. I cannot see any cookies
Is there any way a new image upload from a PHP form sent to
I am using php script to upload file on some ftp server. When I
I need to write a script to upload big Files (~2GB+) to a server.
I have a script which uploads data to my web server running Apache/PHP 5.3,
I' running a php script to insert events that I take from a CSV
I would like to upload files (php sites/applications) to given directory and run them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.