简体   繁体   中英

PHP - Imagick fatal error, no explanation

So, I am trying to convert a pdf file into a jpeg file, but when i read the pdf file with readImage($_FILES["fileinput"]["tmp_name"]) the fatal error is given. I get the file via html from which you can see below.

HTML FORM:

<form enctype="multipart/form-data" class="generalForm" action="../includes/connect.php" method="POST">
            <label class="headLabel">DODAJ</label>
            <br>
            <br>
            <input class="inputTextSub" id="naziv" name="naziv" type="text">
            <br>
            <br>
            <input class="inputTextSub" id="opis" name="opis" type="text">
            <br>
            <br>
            <input class="inputTextSub" id="datumz" name="datumz" type="date">
            <br>
            <br>
            <input type="file" name="inputfile" id="file" class="inputfile" />
            <br>
            <br>
            <br>
            <input class="button" style="margin-top:2em;" name="save" type="submit" value=" shrani ">
        </form>

and then here is the code in php that i execute when user presses the button.

    if(isset($_POST['save'])){
    if(!$_POST['naziv']==""&&!$_POST['opis']==""&&!$_POST['datumz']==""
    &&!$_POST['datumk']==""&&isset($_POST['pr'])
    &&isset($_POST['format'])&&$_FILES['inputfile']['size']>0){
        $naziv = $_POST['naziv'];
        $opis = $_POST['opis'];
        $datumz = $_POST['datumz'];
        $datumk = $_POST['datumk'];
        $pr = $_POST['pr'];
        $format = $_POST['format'];
        $modId = $_SESSION['mod_id'];
        $file = file_get_contents($_FILES['inputfile']['tmp_name']);


                 $im = new Imagick();
/*THIS LINE*/    $im->readImage($_FILES['inputfile']['tmp_name'].'[0]');
                 $im->writeImage("lala.jpg");

and finnaly, the devil himself:

Fatal error: in C:\\xampp\\htdocs\\mod\\includes\\connect.php on line 49

Please help, im dying with this.

It look like as you are using bad syntax.

$_FILES['inputfile']['tmp_name'].'[0]'

I think you wanted to do something like this $_FILES['inputfile']['tmp_name'][0]

If still it gives you error, try to debug it like this :

//$im = new Imagick();
//$im->readImage($_FILES['inputfile']['tmp_name'].'[0]');
//$im->writeImage("lala.jpg");
echo "<pre>";
print_r($_FILES['inputfile']['tmp_name']);

and check if element [0] exists or not.

If [0] element exists than replace this line $_FILES['inputfile']['tmp_name'][0] with $im->readImage($_FILES['inputfile']['tmp_name'].'[0]');

If [0] element doesn't exists than use $im->readImage($_FILES['inputfile']['tmp_name'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM