mrravee Posted October 7, 2019 Share Posted October 7, 2019 <?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" Quote Link to comment Share on other sites More sharing options...
gw1500se Posted October 7, 2019 Share Posted October 7, 2019 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'. Quote Link to comment Share on other sites More sharing options...
mrravee Posted October 7, 2019 Author Share Posted October 7, 2019 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 Quote Link to comment Share on other sites More sharing options...
mrravee Posted October 7, 2019 Author Share Posted October 7, 2019 (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 October 7, 2019 by mrravee Quote Link to comment Share on other sites More sharing options...
gw1500se Posted October 7, 2019 Share Posted October 7, 2019 Please explain why you want to change the file type? That makes no sense to me. Quote Link to comment Share on other sites More sharing options...
mrravee Posted October 7, 2019 Author Share Posted October 7, 2019 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" Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 7, 2019 Share Posted October 7, 2019 Have you read the manual on the "str_replace" and "implode" functions? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted October 7, 2019 Share Posted October 7, 2019 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 (.). Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 8, 2019 Share Posted October 8, 2019 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. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted October 8, 2019 Share Posted October 8, 2019 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 8, 2019 Share Posted October 8, 2019 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.