Jump to content
mrravee

error can someone help me imagepng code

Recommended Posts

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include 'helpers.php';

$foldername = uniqid();
 
$destination = "vierkant/$foldername";
$locatie = "circles/$foldername";


createDirectory($locatie);
createDirectory($destination);






    $upload_files = [];

    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
        move_uploaded_file(
            $_FILES['file']['tmp_name'][$i],
            $destination . '/' . $_FILES['file']['name'][$i]
        );

        $target_name = $_FILES['file']['name'][$i];

        // Remove the extension and replace it with .png.

         imagepng(imagecreatefromstring(file_get_contents($_FILES["file"]["tmp_name"] )), "output.png");




       // One method for this is to use the "explode" function with a dot as a delimiter.


// variable we are going to split


  print_r (explode(".",$target_name));



        // Then replace the last part with png and then stick the string back together with "implode"

        $upload_files[] = [
            'square' => $destination . '/' . $_FILES['file']['name'][$i],
            'circle' => $locatie . '/' . $_FILES['file']['name'][$i],
        ];
    }







foreach ($upload_files as $loopdata) {
         print_r($loopdata['circle']);

        toCircle($loopdata['square'],$loopdata['circle'],'450');


}

 

I have to do this but i get this error: https://ibb.co/mFzxqXL

can anyone help me?

// Remove the extension and replace it with .png.


// One method for this is to use the "explode" function with a dot as a delimiter.

// variable we are going to split:

  // Then replace the last part with png and then stick the string back together with "implode"

Share this post


Link to post
Share on other sites

You can't just change the file type and expect it to work. A better method is to only allow 'png' file type. Use pathinfo() to check the file type and issue an error if it is not 'png'.

Share this post


Link to post
Share on other sites

 

49 minutes ago, gw1500se said:

You can't just change the file type and expect it to work. A better method is to only allow 'png' file type. Use pathinfo() to check the file type and issue an error if it is not 'png'.

thanks it work

Share this post


Link to post
Share on other sites
Posted (edited)

i need the last step now.

replace the last part with png and then stick the string back together with "implode"

 

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include 'helpers.php';

$foldername = uniqid();
 
$destination = "vierkant/$foldername";
$locatie = "circles/$foldername";


createDirectory($locatie);
createDirectory($destination);






    $upload_files = [];

    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
        move_uploaded_file(
            $_FILES['file']['tmp_name'][$i],
            $destination . '/' . $_FILES['file']['name'][$i]
        );

        $target_name = $_FILES['file']['name'][$i];

        // Haal de extensie eraf en vervang hem door .png.
        $part = explode(".",$target_name);

        end($part);
        $key = key($part);
        reset($part);
        $part [$key] = "png";

print_r ($part);










        //replace the last part with png and then stick the string back together with "implode"






        $upload_files[] = [
            'square' => $destination . '/' . $_FILES['file']['name'][$i],
            'circle' => $locatie . '/' . $_FILES['file']['name'][$i],
        ];
    }







foreach ($upload_files as $loopdata) {
         print_r($loopdata['circle']);

        toCircle($loopdata['square'],$loopdata['circle'],'450');


}

 

Edited by mrravee

Share this post


Link to post
Share on other sites

Please explain why you want to change the file type? That makes no sense to me.

Share this post


Link to post
Share on other sites
11 minutes ago, gw1500se said:

Please explain why you want to change the file type? That makes no sense to me.

its something what i have to do for internship but i cant find a way how i place this together: replace the last part with png and then stick the string back together with "implode"

Share this post


Link to post
Share on other sites

Have you read the manual on the "str_replace" and "implode" functions?

Share this post


Link to post
Share on other sites

Since pathinfo() breaks is all down for you, just put it back together replacing the type. You can use implode or just concatenate the pieces (.).

Share this post


Link to post
Share on other sites

It still makes no sense to be altering the filename extension.  Once you do that most applications will not be able to decipher the file since it won''t be in the format indicated by whatever extension you use.   Think about it - you change in image file name to end with ".txt".  Then when you click on it your text editor tries to open it and all it gets is gibberish.

Share this post


Link to post
Share on other sites

Perhaps it is just an exercise in string handling that has no useful purpose. It would not be the first time for such an assignment.

Share this post


Link to post
Share on other sites

If that is ALL it is, then we should let the OP do her homework herself.  Does no good for us to do it.  She is on the first page of a long learning process that involves actual research to become proficient at it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.