Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End can only upload image files not audio

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #178192
    MBM
    Participant

    I have adapted a script I use to upload images into a folder to upload audio but audio files do not save – neither the path into the table or the audio into the folder. Is getimagesize the problem because I need to check other formats?

    <?php
    include "connect.php";
    require "authenticate.php";
    error_reporting(E_ERROR);
    $message = $_GET['message'];
    //function to check for valid image formats
    function uploadfile($dir){
    if(!empty($_FILES)){
    $url ='';  
    $file = getimagesize($_FILES["file"]["tmp_name"]);
    $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "PNG", "GIF", "mp3");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if ((($file["mime"] == "image/gif")
    || ($file["mime"] == "image/jpeg")
    || ($file["mime"] == "image/jpg")
    || ($file["mime"] == "image/pjpeg")
    || ($file["mime"] == "image/x-png")
    || ($file["mime"] == "image/png")
    || ($file["mime"] == "audio/mp3")
    )
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
        {
        if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        }
        else
        {
        $path = $dir . $_FILES["file"]["name"];
        {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        $dir . $_FILES["file"]["name"]);
        $path = $dir . $_FILES["file"]["name"];
        }
        }
        }
    else
        {
        $message = "Wrong format";
        }
    }
    return $path;
    }
    #178200
    chrisburton
    Participant

    Is getimagesize the problem because I need to check other formats?

    Probably. It should return false. Did you check?

    #178203
    MBM
    Participant

    It doesn’t return false. I’m not sure how to change the code to check all formats.

    #178204
    chrisburton
    Participant

    Instead of getimagesize, try FILEINFO_MIME_TYPE

    #178209
    MBM
    Participant

    I tried :

    $file = FILEINFO_MIME_TYPE($_FILES["file"]["tmp_name"]);

    Call to undefined function FILEINFO_MIME_TYPE()

    Then added :

    define('FILEINFO_MIME_TYPE', 16);

    Same error.

    #178210
    chrisburton
    Participant

    @MBM What version of PHP are you running?

    Try FILEINFO_MIME, first. If that doesn’t work try mime_content_type. Although I would recommend upgrading.

    #178211
    MBM
    Participant

    5.3. FILEINFO_MIME gave the same problem.

    #178212
    chrisburton
    Participant

    @MBM Where are you developing this? Locally? Live server?

    #178214
    MBM
    Participant

    It’s live. I have a website for creating trading cards – form and image data.

    http://thetradingcardgenerator.com

    I’m trying to adapt the code so I can upload other data formats for another website but am testing it on my server.

    #178218
    chrisburton
    Participant

    @MBM Do you have access to the php.ini file?

    #178219
    MBM
    Participant

    The code is correct and there’s an issue at the server end?

    register_globals = off
    allow_url_fopen = off
    
    expose_php = Off
    max_input_time = 60
    variables_order = "EGPCS"
    extension_dir = ./
    upload_tmp_dir = /tmp
    precision = 12
    SMTP = ******
    url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="
    
    ; Only uncomment zend optimizer lines if your application requires Zend Optimizer support
    
    ; -- Be very careful to not to disable a function which might be needed!
    ; -- Uncomment the following lines to increase the security of your PHP site.
    
    ;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru,
    ;             phpinfo, exec, system, dl, fsockopen, set_time_limit,
    ;                     popen, proc_open, proc_nice,shell_exec,show_source,symlink"
    #178221
    chrisburton
    Participant

    @MBM

    The code is correct and there’s an issue at the server end?

    How is the code correct if it’s not working?

    #178222
    MBM
    Participant

    Sorry I thought you were suggesting the problem was server side and not the code itself.

    #178223
    chrisburton
    Participant

    PHP is server side. Anyway, you said the code you are working on is on a live server and not locally (Xamp, Mamp, Wamp), correct?

    #178224
    MBM
    Participant

    No. I’m testing live. I don’t need to test locally. Image upload works. MP3 does not.

Viewing 15 posts - 1 through 15 (of 18 total)
  • The forum ‘Back End’ is closed to new topics and replies.