Image Upload Breaks in PHP 8.1 - No uploaded images to select in editor #4689
Unanswered
clonefunnels
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Please help! Image uploading works in PHP 7.4 but it breaks in PHP 8.1 and stops showing preview images.
It looks like the uploads are working, but there are no images in the editor to select.
Do you see anything in this code that would break it in PHP 8.1?
assetManager: {
storageType : '',
storeOnChange : true,
storeAfterUpload : true,
upload: '../images',
assets : [ ],
uploadFile: function(e) {
var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
var formData = new FormData();
for(var i in files){
formData.append('file-'+i, files[i]) //containing all the selected images from local
}
$.ajax({
url: 'upload_image.php',
type: 'POST',
data: formData,
contentType:false,
crossDomain: true,
dataType: 'json',
mimeType: "multipart/form-data",
processData:false,
success: function(result){
var myJSON = [];
$.each( result['data'], function( key, value ) {
myJSON[key] = value;
});
var images = myJSON;
editor.AssetManager.add(images);
}
});
},
},
upload_image.php
if($_FILES)
{
$resultArray = array();
foreach ( $_FILES as $file){
$fileName = $file['name'];
$tmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileType = $file['type'];
if ($file['error'] != UPLOAD_ERR_OK)
{
error_log($file['error']);
echo JSON_encode(null);
}
move_uploaded_file($tmpName, $targetPath);
$response = array( 'data' => $resultArray );
echo json_encode($response);
}
All reactions