HTTP Error 500 while uploading files by adding

I am stuck in the download part. I am using uploadify script. Regular files load successfully, but when I get tired of loading the file name using file's.jpg , an HTTP 500 error occurs. My add script:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
  $('#attachment').uploadify({
    'uploader'  : '<?php echo base_url();?>web/uploadify/uploadify.swf',
    'script'    : '<?php echo base_url();?>web/uploadify/uploadify.php',
    'cancelImg' : '<?php echo base_url();?>web/uploadify/cancel.png',   
    //'folder'    : '../../uploads/project_files/',
    'folder'    : '/admin_panel_new/assets/plupload/uploads/',
    'auto'      : true,
    'multi'       : true,   
    'hideButton': false,
    'buttonImg' :  "<?php echo base_url()?>images/attachment_image.gif",    
    'width'     : 132,
    'height'    : 25,
    'removeCompleted' : false,
    'onSelect' : function(file) {   
            $('#submitFeedback').val('Please wait while uploading...');
            $('#submitFeedback').attr('disabled','disabled');           
    },
    'onComplete'  : function(event, ID, fileObj, response, data) {
        if($('#fileList').val()!='')    
            $('#fileList').val($('#fileList').val()+','+response);                      
        else
            $('#fileList').val(response);   
        //alert($('#fileList').val());  

        $('#submitFeedback').removeAttr('disabled');
        $('#submitFeedback').val('Post Feedback');              
    },
    'onError' : function(event, queueID, fileObj, errorObj) { alert(errorObj.type + ' ' + errorObj.info ); }
  });
});
</script>

I tried many other solutions, but no luck.

My uploadify.php code:

<?php
$targetFolder = $_POST['targetFolder']; // Relative to the root
$unik =$_POST['timestamp'];

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.$_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png','txt'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        //
        echo $unik.'_'.$_FILES['Filedata']['name'];
    } else {
        echo 'Invalid file type. Upload Failed';
    }
}
?>

Images of loading errors look like this: enter image description here

If anyone has a solution, please help. Thank.

+4
source share
1 answer

If the problem occurs only with single quotation file names, the first thing I would like to see is

$_FILES['Filedata']['name']

, , , move_uploaded_file. .

, , , . addslashes.

$targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.str_replace("'","",$_FILES['Filedata']['name']);
0

Source: https://habr.com/ru/post/1534419/


All Articles