Howdy, Stranger!

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

Unable to upload files
  • When I use uploadify I get blank names for the file and it does not upload. However, using a simple form and the same uploadify.php the file uploads fine. I created a txt file to try and debug what is going on.

    Here is the upload file:

    <script type=\"text/javascript\">
    $(document).ready(function() {
    $(\"#uplFile\").uploadify({
    'uploader' : '/cms/uploadify/example/scripts/uploadify.swf',
    'script' : '/cms/uploadify/example/scripts/uploadify.php',
    'cancelImg' : '../cancel.png',
    'multi' : true
    });
    });
    </script>


    <input id=\"uplFile\" name=\"uplFile\" type=\"file\" /> 
    <a href=\"javascript:$('#uplFile').uploadifyUpload();\">Upload Files</a> |
    <a href=\"javascript:$('#uplFile').uploadifyClearQueue();\">Clear Queue</a>



    Here is uploadify.php:

    if (!empty($_FILES)) {
    $tempFile = $_FILES['uplFile']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . '\\images\\uploads\\test\\';
    $fileName = $_FILES['uplFile']['name'];
    $targetFile = $targetPath . $fileName;

    @ $fp = fopen($_SERVER['DOCUMENT_ROOT'] . \"\\images\\uploads\\test\\output.txt\", \"wb\");
    fwrite($fp, \"Saving \" . $tempFile . \" (formerly \" . $fileName . \") to \" . $targetFile . \"\r\n\");

    if (move_uploaded_file($tempFile,$targetFile)) {
    fwrite($fp, \"Success\r\n\");
    } else {
    switch ($_FILES['uplFile'] ['error'])
    { case 1:
    fwrite($fp, \"The file is bigger than this PHP installation allows\r\n\");
    break;
    case 2:
    fwrite($fp, \"The file is bigger than this form allows\r\n\");
    break;
    case 3:
    fwrite($fp, \"Only part of the file was uploaded\r\n\");
    break;
    case 4:
    fwrite($fp, \"No file was uploaded\r\n\");
    break;
    }
    }
    fclose($fp);

    echo \"1\";
    }


    Here is the debug file using uploadify:

    Saving (formerly ) to e:\\wwwroot\images\uploads\test\

    Here is the debug file using my simple form page:

    Saving c:\TEMP\php428.tmp (formerly uploadimage.jpg) to e:\\wwwroot\images\uploads\test\uploadimage.jpg

    What is causing this? I did not put the js and css links on here but they are correct. Thanks for any help you can give.
  • have you tried removing the front / on the script parameter?

    Also this
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . '\\images\\uploads\\test\\';
    would cause you problems. use \\ when enclosed in " but only a single \ when enclosed in single '
  • Thanks for the response. I resolved that but am getting the same results. Here are the new files.

    index.php:
    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
    <title>Uploadify Example Script</title>
    <link href=\"css/default.css\" rel=\"stylesheet\" type=\"text/css\" />
    <link href=\"css/uploadify.css\" rel=\"stylesheet\" type=\"text/css\" />
    <script type=\"text/javascript\" src=\"scripts/jquery-1.3.2.min.js\"></script>
    <script type=\"text/javascript\" src=\"scripts/swfobject.js\"></script>
    <script type=\"text/javascript\" src=\"scripts/jquery.uploadify.v2.1.0.min.js\"></script>
    <script type=\"text/javascript\">
    $(document).ready(function() {
    $(\"#uplFile\").uploadify({
    'uploader' : 'scripts/uploadify.swf',
    'script' : 'scripts/uploadify.php',
    'cancelImg' : '../cancel.png',
    'multi' : true
    });
    });
    </script>
    </head>

    <body>
    <input id=\"uplFile\" name=\"uplFile\" type=\"file\" /> <a href=\"javascript:$('#uplFile').uploadifyUpload();\">Upload Files</a> | <a href=\"javascript:$('#uplFile').uploadifyClearQueue();\">Clear Queue</a>
    </body>
    </html>


    uploadify.php:
    if (!empty($_FILES)) {
    $tempFile = $_FILES['uplFile']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . \"\\images\\uploads\\test\\\";
    $fileName = $_FILES['uplFile']['name'];
    $targetFile = $targetPath . $fileName;

    @ $fp = fopen($_SERVER['DOCUMENT_ROOT'] . \"\\images\\uploads\\test\\output.txt\", \"wb\");
    fwrite($fp, \"Saving \" . $tempFile . \" (formerly \" . $fileName . \") to \" . $targetFile . \"\r\n\");

    if (move_uploaded_file($tempFile,$targetFile)) {
    fwrite($fp, \"Success\r\n\");
    }

    fclose($fp);

    echo \"1\";
    }