jQuery Multiple File Upload Pluginv1.31 and PHP

Using the multipart/form-data in the PHP upload code

Page 1 of 1

3 Replies - 11113 Views - Last Post: 20 April 2009 - 05:50 AM Rate Topic: -----

#1 mothermugger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-March 09

jQuery Multiple File Upload Pluginv1.31 and PHP

Posted 29 March 2009 - 03:57 PM

Here is the starting page for my multi-file upload project:

http://www.crossroad...s/lastpost1.htm

This part works fine and there was great documentation on how to set it up. And I have it working with ASP just fine.
But now I need to set it up for PHP and I am having some trouble understanding how to work with the data that is sent to my php file. All I have for code on the PHP side right not is something that shows me that the data is getting to the php page.

Here is my PHP code:
<?php
$return = array();
$return[ 'files' ] = $_FILES;
$return[ 'post' ] = $_POST;

echo json_encode( $return );
?>

I know this doesn't even start to get the job done on the upload part. Which I have done with a single file at a time in PHP like so:
<?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!";
}
?>

I am having a total disconnect with understanding how to get my mutiple files upload data to work here.

Is This A Good Question/Topic? 0
  • +

Replies To: jQuery Multiple File Upload Pluginv1.31 and PHP

#2 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: jQuery Multiple File Upload Pluginv1.31 and PHP

Posted 29 March 2009 - 04:10 PM

$_FILES is an array so each file you upload would be placed withing its own part of the array, so using a foreach loop would help you work through each file
Was This Post Helpful? 0
  • +
  • -

#3 mothermugger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-March 09

Re: jQuery Multiple File Upload Pluginv1.31 and PHP

Posted 29 March 2009 - 07:57 PM

View PostAuzzie, on 29 Mar, 2009 - 03:10 PM, said:

$_FILES is an array so each file you upload would be placed withing its own part of the array, so using a foreach loop would help you work through each file


Yes a loop it seems it must be part of the puzzle. But the normal things you would do with an array don't seem to work with the $_FILES - like echo $_FILES[0]; will not produce a file name?!? My first program in my post here does show the contents of the post but those contents are presented in a way that is highly formated and it seems that much of the path information to the file on the c: drive is not included, not that I care so much if it would work.

Here is my new code and now I have an error message!
(before I was just getting blank screens)

...above this it loads the Jquery multi-upload js scripts etc
(This part works OK)

choosefile.htm
<form action="uploader.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />

<input type="file" class="multi" name="uploadedfile[]" size="31"/><p>
<font face="Arial Narrow" size="2"></font><input type="submit" value="Upload File" />
<p>
</p>

</form>


UPLOADER.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>
<title>Untitled Page</title>
</head>
<body>
<?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!";
}
?>
</body>
</html>

Error message:
Warning: basename() expects parameter 1 to be string, array given in /home/content/s/p/e/spencedave/html/multi-uploads/uploader.php on line 11

http://www.crossroad...choosefiles.htm
Was This Post Helpful? 0
  • +
  • -

#4 mothermugger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-March 09

Re: jQuery Multiple File Upload Pluginv1.31 and PHP

Posted 20 April 2009 - 05:50 AM

:^: Hey thanks for all the help! I was able to sove the puzzle and now I have a very cool multi file upload using PHP!
Check the demo of my project here:
http://www.ezwayweb....sample_code.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1