Create the controller of an upload file form in zend - php

I have created the elements in the form for an upload document but the form has other elements as well. Now I can't seem to find out a way to upload files because no matter what I do is says "File 'img_file' exceeds the defined ini size" even if I try to save only another field in the form.
$file = new \Zend_Form_Element_File('img_file');
$file->setLabel ( \Zend_Registry::get('config')->form->docFile )
->setRequired(false);
Also added ->setEnctype(\Zend_Form::ENCTYPE_MULTIPART); for the form
Can somebody help me with the controller since I'm using MVC?

Related

How to reference to an image in order to upload it to CloudConvert

I want to use Composer's PHP wrapper to upload an image to CloudConvert. This image will come from a html form which users will fill. In the array that CloudConvert's start() function uses to upload a file, the key/value pair for an image file is:
<?php
$process->start([
"input" => "download",
"file" => "http://url/to/my/file.ext",
"outputformat" => "png",
......
......
],
]);
?>
The value associated with the 'file' key seems as if it must be a public URL. Ideally I would like to use the html form variable as the value for the 'file' key in the array. I've tried using the $_FILES array with both ['tmp_name] and ['name'] but both throw errors. I've also placed an image in the root directory and then used $img_filepath = fopen('./Post_box_Lake_District.jpg', 'r'); but that throws the following error: Uncaught CloudConvert\Exceptions\ApiException: Upload is not allowed in this process state in C:\xampp\htdocs\test_site\vendor\cloudconvert\cloudconvert-php\src\Process.php:80. I presume I could use the URLs for images stored on a file on my server but for the moment I'm storing images in a database. CloudConvert have a facility where users can upload their API but, if possible, I don't want to do that. I want everything to come through my server. So how can I upload images via CloudConvert's API. Thanks for any help in advance.

Adobe upload cannot read stream in PHP

The file is small about 4 to 5Kb.
I am trying to upload a fillable pdf to an Apache server.
The pdf has a submit button which uploads the PDF to a Zend IndexController using
$request=$this->getRequest();
$tempFile=time().'.pdf';
file_put_contents("data/tmp/".$tempFile, $request->getContent());
I am now trying to do the same in Drupal 7 to no avail. $_POST and $_FILES are both empty.
If I use an HTML form the file will upload, however, I want the end user to click on the button within the form.
I also tried
file_put_contents("data/tmp/".$tempFile, "php://input");
Which created the PDF file on the server, but it unfortunately only contains the text "php://input".
Can someone please advise how to do this?
Dale's answer
file_put_contents("data/tmp/".$tempFile, file_get_contents("php://input"));
is correct

Renaming input file before uploading with jquery and laravel

I want to rename input file to be uploaded before sending to laravel.
Basically, i found an another way to rename the file in laravel but in this question I want to rename the file before sending to laravel.
In my case, I'm using jquery upload file, and now I want the input file to be renamed before uploading it. I want to get the new file name that I used to insert in the hidden input text.
Is there any solution to solve this kind of matter?
By the way, thank you in advance! ^_^
Did you check this: File Docs
as per this doc you can do this as follow:
$request->file('photo')->move($destinationPath, $fileName);
where $fileName is an optional parameter that renames the file.
so you can use this like:
$fileName = str_random(30); // any random string
then pass this as above.

Link to file with dynamic name

I am trying to create a job application manager in php. The applicant fills in their details on the web form and presses submit, it is then added to the mysql database. As part of the form is an upload file box to add a covering letter, this will accept files in doc, docx, pdf, rtf, txt . When the file is uploaded it gets renamed to a hidden field in the form called 'applicationID', so a file called My covering letter.doc would become something like 124356456.doc.
The problem I am having is in my application manager I can use while($row = mysql_fetch_array($result)) and then pull out the applicants name etc, but im not sure how to deal with the files. If the file was just named 124356456 I could just link to that using the application id, but because the extension could be a combination of .doc, docx, pdf etc im not sure how to link to it. Ideally it would be something like :
View Covering letter
So what im asking is can I link to a file when I don't know what the extension is, but I know what the file name is ?.
You have to store the extension in your database during the upload.
How to get the extension :
pathinfo($filename, PATHINFO_EXTENSION);
Another solution is to write a function to check if the file exists and return the correct extension.
View Covering letter
<?php
function getFile($path) {
if(file_exists($path.".doc"))
return $path.".doc";
else if(file_exists($path.".docx"))
return $path.".docx";
else if(file_exists($path.".pdf"))
return $path.".pdf";
else if(file_exists($path.".rtf"))
return $path.".rtf";
else if(file_exists($path.".txt"))
return $path.".txt";
}
?>

Manipulating file in PHP without $_FILES

I'm trying to programmatically add a tint to an image. I've done this very easily with a form and the $_FILES array but I need to get the image from a URL, and the images I'm trying to use are on my own server if that is important. Here's a sample code of the working form function
$img = new Upload($_FILES['imgfile']);
Now all I need is something like $img = new Upload(fopen($image_path); But this isn't working... Please help me!!
In the following code, you are passing a $_FILES array structure to your Upload class:
$img = new Upload($_FILES['imgfile']);
The variable $_FILES['imgfile'] itself is an array, consisting of named members such as 'name', 'tmp_name' and others - information about the file that has been passed to PHP by the server receiving the uploaded file.
Your Upload class appears to be designed to handle this sort of structure. It will probably have been designed specifically for handling file uploads, so you may need to modify it a bit to allow it to be passed any file path as a parameter instead of this array structure.
Well, you can fake $_FILES array all right.
the only function you cannot fool with this array is move_uploaded_file() but it seems you don't need it anyway.
but, you know, nobody have an idea what your "new Upload" is.

Categories