• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Get uploaded filename in PHP

Get uploaded filename in PHP 9 years 8 months ago #32052

  • mylo
  • mylo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 3
I have a form where clients can leave a review and optionally upload an image. I am using the SQL mapping to create a new article with this information. However, I'm struggling with getting the filename so I can manipulate it in the "PHP - Script called on form process" area.

"Image" is the name of the upload field. I've tried many things, but this is where I'm at right now...
$image = $_POST['form']['Image'];
$newimage = '<img src="/components/com_rsform/uploads/reviews/' . $image . '" style="float:right; margin:0 0 20px 20px;" />';
$_POST['form']['Review'] = $newimage . $_POST['form']['Review'];
The administrator has disabled public write access.

Get uploaded filename in PHP 9 years 8 months ago #32070

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

File information is not stored in the $_POST variable, you will have to control these from the $_FILES variable. It's content can be viewed, for example, by adding the following code in the "Scripts called on form process" area (backend > Components > RSForm!Pro > Manage Forms > your form > Properties > PHP Scripts) and by submitting the form with a file selected for uploading:

var_dump($_FILES);
die();

More information on the RSForm!Pro specialized scripting areas can be found here.
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.

Get uploaded filename in PHP 9 years 8 months ago #32073

  • mylo
  • mylo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 3
Yes, I already tried using that as suggested in a different post, but it seems the info that it gives is useless.

I'm uploading a file named "ambigram-custom-iphone-case.jpg". When I process the form, using $_POST will output the following...
www. mydomain. com/images/reviews/55ca621f25471-ambigram-custom-iphone-case.jpg

"55ca621f25471-" is prepended to the filename.

The var_dump gives me the following...
File Info: array ( 'form' => array ( 'name' => array ( 'Image' => 'ambigram-custom-iphone-case.jpg', ), 'type' => array ( 'Image' => 'image/jpeg', ), 'tmp_name' => array ( 'Image' => '/home/threedtc/public_html/tmp/phpqtL8Ti', ), 'error' => array ( 'Image' => 0, ), 'size' => array ( 'Image' => 85942, ), ), )

I don't see any usable information there that tells me what the prepended text ends up being.
Last Edit: 9 years 8 months ago by mylo.
The administrator has disabled public write access.

Get uploaded filename in PHP 9 years 8 months ago #32077

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

This random sequence is automatically added by RSForm!Pro to prevent overwriting files if these have the same name. Nevertheless, you can either:

- control this sequence from the File Upload configuration (more precisely 'File prefix' as this allows using PHP code). For example, you can use a 'Support Ticket', add it's value to the File prefix, thus, using "Scripts called on form process", you can retrieve both the file prefix (Support Ticket value) and the file name through $_FILES.

- or, move your script within "Scripts called after form process" area. Here, you can use a similar as the following snippet:
list($replace, $with) = RSFormProHelper::getReplacements($SubmissionId);
//$uploadPath will store the exact path of your file, including its prefix-name.
$uploadPath = str_replace($replace, $with, '{myFileUpload:path}');

Replace myFileUpload with your File Upload element exact name.

Other specialized File Upload placeholders are listed here.
This is not official customer support. To receive your support, submit a support ticket here.
Last Edit: 9 years 8 months ago by adrianp.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!