lets say I want to use this pHp code

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
KingSparta
 
 
Posts: 305
Joined: Tue Dec 08, 2020 6:00 pm
Location: Earth

lets say I want to use this pHp code

Post 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.";
  }
}
?>
Retired military, Airborne, Air Assault, and Helicopter Flight Wings.
Enjoys model trains, the internet, and ham radio. Located in Fayetteville, NC, USA.
https://MyAAGrapevines.com
User avatar
BaconFries
 
 
Posts: 5952
Joined: Thu Aug 16, 2007 7:32 pm

Re: lets say I want to use this pHp code

Post 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
User avatar
Pablo
 
Posts: 23493
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: lets say I want to use this pHp code

Post 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.
User avatar
KingSparta
 
 
Posts: 305
Joined: Tue Dec 08, 2020 6:00 pm
Location: Earth

Re: lets say I want to use this pHp code

Post 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.
Retired military, Airborne, Air Assault, and Helicopter Flight Wings.
Enjoys model trains, the internet, and ham radio. Located in Fayetteville, NC, USA.
https://MyAAGrapevines.com
Post Reply