Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Yet another mySQL question
  • I've seen tons of threads on this board regarding my question, yet none seems to give me the answer I'm looking for.

    Basically, I'm trying to insert the uploaded file name into my database.

    The script works; I can upload files and they show up in my folder fine. Now here's my thought process:

    I have a database with form data, and I want to be able to upload the original PDF of that form to be associated with that particular entry. On the page that is displaying he data, in my URL there is a query string that is called ?aoi=11 where the number is the ID of that entry in the database. So I figure I could just pass that ID into the uploadify.php file by sending that same ID number in a query string:

    <input id=\"fileInput\" name=\"fileInput\" type=\"file\" />
    <script type=\"text/javascript\">// <![CDATA[
    $(document).ready(function() {
    $('#fileInput').uploadify({
    'uploader' : '/includes/js/uploadify/uploadify.swf',
    'script' : '/includes/js/uploadify/uploadify.php?aoiid=<?php echo \"$aoiid\";?>',
    'cancelImg' : '/includes/js/uploadify/cancel.png',
    'auto' : true,
    'folder' : '/aoipdf',
    'buttonText' : 'Upload AOI',
    'fileDesc' : 'PDF',
    'fileExt' : '*.pdf'
    });
    });
    // ]]></script>


    So then in my uploadify.php file, I've got it so that it will insert the file name into the database under the correct ID:

    include('../../conn.php');
    $aoiid = @$_GET['aoiid'];

    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    // $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
    // Uncomment the following line if you want to make the directory if it doesn't exist
    // mkdir(str_replace('//','/',$targetPath), 0755, true);
    mysql_query(\"INSERT INTO aoi WHERE id='$aoiid' (filename) VALUES ('\" . $targetFile . \"');\" );
    move_uploaded_file($tempFile,$targetFile);
    echo \"1\";
    // } else {
    // echo 'Invalid file type.';
    // }
    }


    However.... this isn't doing anything. Am I going about this the wrong way?
  • Ah ha!


    <input id=\"fileInput\" name=\"fileInput\" type=\"file\" />
    <script type=\"text/javascript\">// <![CDATA[
    $(document).ready(function() {
    $('#fileInput').uploadify({
    'scriptData' : {'aoiid': '<?= $_GET['aoiid']; ?>'},
    'uploader' : '/includes/js/uploadify/uploadify.swf',
    'script' : '/includes/js/uploadify/uploadify.php',
    'cancelImg' : '/includes/js/uploadify/cancel.png',
    'auto' : true,
    'folder' : '/aoipdf',
    'buttonText' : 'Upload AOI',
    'fileDesc' : 'PDF',
    'fileExt' : '*.pdf'
    });
    });
    // ]]></script>



    include('../../conn.php');
    $aoiid = $_REQUEST['aoiid'];

    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    // $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
    // Uncomment the following line if you want to make the directory if it doesn't exist
    // mkdir(str_replace('//','/',$targetPath), 0755, true);
    mysql_query(\"UPDATE aoi SET filename = '\" . $targetFile . \"' WHERE id='$aoiid'\");
    move_uploaded_file($tempFile,$targetFile);
    echo \"1\";
    // } else {
    // echo 'Invalid file type.';
    // }
    }


    It works!