Page 1 of 1

lets say I want to use this pHp code

Posted: Thu May 22, 2025 8:30 am
by KingSparta
Let's say I want to use this PHP code to upload files. What do I need to do with it to make it run in wysiwyg?
Any reading material? It is a complete PHP code for uploading

Code: Select all

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

// Check if file already exists
if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
}

// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
  echo "Sorry, your file is too large.";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
  echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
?>

Re: lets say I want to use this pHp code

Posted: Thu May 22, 2025 8:56 am
by BaconFries
You can use the following HTML Object to add/use external code scripts but you should yourself have a basic understanding of how to insert correctly in the html.

There is already a couple of extensions to use that may be easier.
https://www.wysiwygwebbuilder.com/fileuploader.html
https://www.wysiwygwebbuilder.com/dropzone.html

Re: lets say I want to use this pHp code

Posted: Thu May 22, 2025 8:58 am
by Pablo
This code is already built-in so there is no need to add it manually.

Step 1
Create a form with a "File upload" object

Step 2
Enable 'Use built-in PHP form processor script'

Step 3
Advanced -> File Upload -> Upload to a folder on the server

Note about the code: if it works in any other editor then it will also work in WWB.

Re: lets say I want to use this pHp code

Posted: Thu May 22, 2025 7:28 pm
by KingSparta
Pablo, I am going to use your extension that BaconFries recommended.

I think I found a problem with the upload that is in the wizard. Tomorrow I will make sure and report it if so.

thanks both.