Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:44:45+00:00 2026-05-30T18:44:45+00:00

I have some code that uses a multi-part form and HTML5 file object to

  • 0

I have some code that uses a multi-part form and HTML5 file object to upload an image (or movie, ppt, etc) to a server, where PHP receives it and writes to disk. However, PHP doesn’t appear to be writing to disk at all.

Javascript:

function uploadFile (file, fileid) {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            window["fn"+fileid] = xhr.responseText;
            $("progress"+fileid).innerHTML = "<a href=\""+window["fn"+fileid]+"\">"+window["fn"+fileid]+"</a>";
        }
    }
    var a = new Element("div");
    a.id = "progress"+fileid;
    a.setStyle("background-color", "#4682B4");
    a.setStyle("height", "20px");
    a.setStyle("width", "0px");
    $("progress-wrapper").adopt(a);
    xhr.upload.onprogress = function(e, a) {
        var percent = Math.round((e.loaded*150)/e.total);
        var acperct = Math.round(percent/1.5);
        $("progress"+fileid).setStyle("width", percent);
        $("progress"+fileid).innerHTML = file.name+" "+acperct+"%";
    }

    alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNNOPQRSTUVWXYZ1234567890".split("");
    tmp_name = [];
    for (i = 0; i < 6; i++) tmp_name[i] = alpha[Math.floor(Math.random() * alpha.length)];
    xhr.open("POST", "upload.php", true);
    xhr.setRequestHeader("Content-Type", "multipart/form-data");
    xhr.setRequestHeader("size", file.size);
    xhr.setRequestHeader("name", file.name);
    xhr.setRequestHeader("type", file.type);
    xhr.setRequestHeader("tmp_name", ""+tmp_name.join(""));
    xhr.send(file);
}

PHP:

<?
    function apache_request_headers() { 
        foreach($_SERVER as $key=>$value) { 
            if (substr($key,0,5)=="HTTP_") { 
                $key=str_replace(" ","-",ucfirst(strtolower(str_replace("_","_",substr($key,5))))); 
                $out[$key]=$value; 
            }else{ 
                $out[$key]=$value; 
    } 
        } 
        return $out; 
    } 

    $headers = apache_request_headers();
    $contents = file_get_contents("php://input");
    echo $contents;
    $ffilename=$headers["tmp_name"].$headers["name"];
    $all = array('png','jpeg','jpg','gif','mov','txt','wmv','pdf');
    $fh = fopen("upload/".$ffilename, "w+");
    fwrite($fh, $contents);
    fclose($fh);
    echo "upload/".$ffilename;
?>

What happens is that there’s either nothing in the written file or the text upload/.

What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:44:46+00:00Added an answer on May 30, 2026 at 6:44 pm

    You didn’t specify which platform you are running this code on, but if it’s unix-based, check the permissions on the upload directory – make sure that write permissions are set for the owner/group that apache runs as. As a quick test, do chmod 0777 upload/ and see if you file shows up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that uses Open XML to open up a .docx file,
I have written some code that uses attributes of an object: class Foo: def
I have some code that uses a form.submit() to open up another window when
Hi I have some code that uses block RandomAccessFile file = new RandomAccessFile(some file,
I have some code that uses ctypes to try to determine if the file
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that uses the Oracle function add_months to increment a Date
I have some Java code that uses curly braces in two ways // Curly
I have some old code that uses qsort to sort an MFC CArray of
We have some code kicking around that uses this old internal Sun package for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.