wp_upload_bits - unable to upload files due to a permissions issue - php

I have this code inside a WordPress custom plugin I'm working on. I need to upload a pdf file and I'm getting from the client a base64 that is created using html2pdf javascript library.
$pdf_name = 'attached_file_01991';
$pdf_decoded = base64_decode($customer_pdf);
//
$upload = wp_upload_bits($pdf_name, null, $pdf_decoded);
I've noticed that the upload will not start, it will give me an error about permissions, it say that I don't have enough permissions to upload the file.
I've just moved the function in the code, previously it worked fine and I was able to upload pdf files that were generated from the client side.
Is there another way I can use to programmatically upload files in wordpress? I need to use the file as an attachment of emails, so base64 is the best way I have at the moment.

Related

Laravel - edit pdf with FPDF with a soruce file from s3

Im working on a Laravel backend and I need to edit a PDF file allocated in a s3 bucket. When I try opening the PDF with $pdf->setSourceFile($url) I get an error saying Given stream is not seekable!
I can get the file contents using Storage::disk(ENV('FILESYSTEM'))->url($url);, and return it to the front end and that works fine, so I know the path and the permissions are correct. I would like to the content to the setSourceFile($contents) method, intead of the url. is there any way to do this?
By the way, Im using the Laravel filesystem
Edit: I have tried copying the file from s3 to the server and then open it with PDF. I couldn't reach it, but I don't think that's a good way to do it.
First of all: You cannot edit a PDF document with FPDI
As the error message says, the source stream needs to be seekable which seems not be the case with the stream wrapper you're currently using.
You should download the file and create a reader instance of it:
$pdf->setSourceFile(StreamReader::createByString($pdfString));

PHP Image Upload - Locked Photos - FTP Error

I've been creating a website in the same way that I usually so, where I add an article + image using HTML & PHP. The difference is that when I upload the photo, even though it displays on the web page, my folder shows an Icon instead of the image (See Below):
As the photos show on the webpage I didn't think much of it, until I tried to upload the website, where I kept getting an FTP upload error on the images. Then when loading the website, I found that none of the images were there.
I'm not sure what the problem is, but when I tried to open one of the photos in Fireworks it says, "Could not open the file. File is locked".
Does anyone know what the probelm is? I'm using the same upload method used previously.

Force Wordpress media library to index files uploaded from ACF file upload field

I've created an ACF file upload field, in order to attach pdf and image files to each post I create.
the problem is, when I want to Re-Use those files - they don't appear in the media library, but they do appear in the "uploads" folder on the server.
Is there a way to force the media library to index those files?
They certainly should be appearing in the media library so it sounds like a configuration issue. Are there any errors appearing when you upload the file? Perhaps also check your server logs to make sure there is nothing being reported when you try and upload the file...

social.png upload viruses as images in php

I know for the fact that there is trojan or malware in php which represents itself as an image. And I also know that to filter out the file upload we use extensions such as .txt or .png.
Is there a way to scan the files manually when they are being uploaded into the server using server built-in antivirus or the server doing this kind of tasks automatically for us? ( I mean particularly in cpanel )
thanks
If you are worried about code being uploaded to your server in the form of an image, simply re-encode the image upon upload. A file containing code with an image extension will throw an error when the encoder tries to process it.

Codeigniter captcha image cannot be written into captcha directory

I have created a login form with captcha image. It works well on my windows operating system. When I uploaded it to the server captcha image is not displayed. CI creates the image but cannot write it into captcha directory (CHMOD = 755) bacuse of permission settings. When I set CHMOD value of the directory to 777 (which I should not) it works well.
Here there is a question similar to mine but proposed and accepted answer is not secure, I guess.
How can I say CI to write the file that it created into the directory using ftp credentials on the fly or is there another way?
I am afraid of encountering further problems like file upload operations (like profile picture change, attachments to the announcements) by the users.
I got around the permission problem by not writing a file at all.
I modified the library in system/plugins/captcha_pi.php to return the image data for inline inclusion. The other return values are the same (timestamp and captcha phrase).
So instead of writing to a file, it returns the inline image content instead.

Categories