Get the name of the files sent by the form

0

I'm trying to get the name of the files after submitting the form:

add_action('gform_after_submission_5', function ($entry, $form) {

    $file_url = $entry['5'];

    $filename = basename($file_url);

}, 10, 2);

When giving a var_dump $file_url; it returns this (I'm uploading only one file for now):

  

And giving a var_dump $filename; returns this:

  

string (17) "stabbing313.jpg"] "

How do I make $ filename not get the quotation marks and bracket?

UPDATE

When you do this:

$foo = explode(",", $file_url[0]);

foreach ($foo as $teste) {
    echo $teste.'<br>';
}

It even returns the URLs with the brackets:

  

["http: //winds.local/wp-content/uploads/2016/04/WOLVERINE-THE-X-MEN-11-AVX-Tie-In10.jpg"   "http: //winds.local/wp-content/uploads/2016/04/stabbing324.jpg"]

    
asked by anonymous 25.04.2016 / 21:29

2 answers

1

Instead of var_dump. Try to do this:

echo $file_url[0];

If the output you posted is complete, there is an array containing a string

But if the content of the string is: "["http://winds.local/wp-content/uploads/2016/04/stabbing312.jpg"]" . You can try to remove the characters " , [ and ] as follows:

$file_url = substr($file_url,2,strlen($file_url)-2);
$file_url = substr($file_url,0,strlen($file_url)-2);

echo $file_url;

You can also use eval , concatenating in the string, an assignment in an array, then taking the value of the form I initially suggested, but I do not think this is very secure. Better to extract the characters in the "arm".

    
25.04.2016 / 21:35
0

If it's the case of a upload I always get it this way:

$_FILES['arquivo']['name']
    
26.04.2016 / 05:40