Note that there are some explanatory texts on larger screens.

plurals
  1. POARRAY is preceding renamed filenames after upload - PHP
    text
    copied!<p>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"<br> ie: <code>ArrayTest Document v1.0.pdf</code><br> I am fairly confident it isn't my <code>$newfn</code> variable as I display that in a table and it doesnt show up.</p> <pre><code>//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' =&gt; '.png', 'image/gif' =&gt; '.gif', 'image/jpeg' =&gt; '.jpg', 'image/bmp' =&gt; '.bmp', 'application/pdf' =&gt; '.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."; } } </code></pre> <p>I feel like it's related to my <code>$FILES['uploaded']</code> section in the <code>move_uploaded_file</code> command. I've tried googling but as soon as I mention "Array" my google results are nothing remotely the same.</p> <p><strong>Ok so thanks to below I solved it. For anyone in the future I removed the entire <code>$_FILES</code> array so the code reads as</strong></p> <pre><code>//if its a new file, change name and upload if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], $directory . $newfn)) </code></pre> <p>Everything now uploads with the correct name structure. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload