Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion File Upload Question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bobbie  
View profile  
 More options Mar 19, 11:38 am
From: Bobbie <bobbie.st...@gmail.com>
Date: Thu, 19 Mar 2009 08:38:08 -0700 (PDT)
Local: Thurs, Mar 19 2009 11:38 am
Subject: Re: File Upload Question
I'm currently not specifying a MIME type, do I need to do this?  Here
is the PHP code I'm using:

<?php
$target_path = "uploads/";

$target_path = $target_path.basename($_FILES['uploadedfile']
['name']);

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
$target_path))
{
        echo "The file ".basename($_FILES['uploadedfile']['name'])." has been
uploaded";

}

else
{
        echo "There was an error uploading the file, please try again!";
}

?>

On Mar 19, 10:11 am, Carl Whalley <carl.whal...@googlemail.com> wrote:

> Sure its not the MIME type not being defined correctly on the server?
> Try changing the extensions to txt, bin, etc and if you see a pattern
> where some work and others don't then thats the culprit.

> --
> Android Academy:http://www.androidacademy.com

> On Mar 18, 8:36 pm, Bobbie <bobbie.st...@gmail.com> wrote:

> > I have included my code below.  I have the code working for image
> > uploads, but was wondering how to get it to work with audio and video
> > files?  Please let me know if you have any suggestions/tutorials.

> >                 // WORKS WITH JPEG FILE -- String existingFileName = "/sdcard/dcim/
> > Camera/1225231027592.jpg";
> >                 String existingFileName = "/sdcard/Music/kryptonite.mp3"; // DOES
> > NOT WORK WITH MP3 FILE
> >                 File uploadFile = new File(existingFileName);
> >                 FileInputStream fileInputStream = new FileInputStream(uploadFile);

> >                 String lineEnd = "\r\n";
> >                 String twoHyphens = "--";
> >                 String boundary = "*****";
> >                 try
> >                 {
> >                         URL connectURL = new URL("http://www.mysite.com/uploads.php");

> >                         // connectURL is a URL object
> >                         HttpURLConnection conn = (HttpURLConnection)
> > connectURL.openConnection();

> >                         // allow inputs
> >                         conn.setDoInput(true);

> >                         // allow outputs
> >                         conn.setDoOutput(true);

> >                         // don't use a cached copy
> >                         conn.setUseCaches(false);

> >                         // use a post method
> >                         conn.setRequestMethod("POST");

> >                         // set post headers
> >                         conn.setRequestProperty("Connection","Keep-Alive");
> >                         conn.setRequestProperty("Content-Type","multipart/form-
> > data;boundary="+boundary);

> >                         // open data output stream
> >                         DataOutputStream dos = new DataOutputStream(conn.getOutputStream
> > ());
> >                         dos.writeBytes(twoHyphens + boundary + lineEnd);
> >                         dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile
> > \";filename=\""+existingFileName +"\"" + lineEnd);
> >                         dos.writeBytes(lineEnd);

> >                         // create a buffer of maximum size
> >                         int bytesAvailable = fileInputStream.available();
> >                         int maxBufferSize = 1024;
> >                         int bufferSize = Math.min(bytesAvailable, maxBufferSize);
> >                         byte[] buffer = new byte[bufferSize];

> >                         // read file and write it into form...
> >                         int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
> >                         while (bytesRead > 0)
> >                         {
> >                                 dos.write(buffer, 0, bufferSize);
> >                                 bytesAvailable = fileInputStream.available();
> >                                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
> >                                 bytesRead = fileInputStream.read(buffer, 0, bufferSize);
> >                         }

> >                         // send multipart form data necesssary after file data...
> >                         dos.writeBytes(lineEnd);
> >                         dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

> >                         // close streams
> >                         fileInputStream.close();
> >                         dos.flush();

> >                         InputStream is = conn.getInputStream();
> >                         int ch;

> >                         StringBuffer b =new StringBuffer();
> >                         while( ( ch = is.read() ) != -1 ) {
> >                                 b.append( (char)ch );
> >                         }

> >                         String s=b.toString();
> >                         dos.close();
> >                 }
> >                 catch (MalformedURLException ex) {
> >                         // Log.e(Tag, "error: " + ex.getMessage(), ex);
> >                 }
> >                 catch (IOException ioe) {
> >                         // Log.e(Tag, "error: " + ioe.getMessage(), ioe);
> >                 }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google