
Hi,
I've been searching the forum for a GOOD example how to send extra post variables to the "upload" script, the upload script uploads more then 1 file.
Anyhow, I'll try to give an example of what I mean. Say, you would like to create a photo album. So you would need to add an input field to add the album name, also you want to send the userid of the person who's creating the album also with a hidden input field.
Is it maybe possible to create a working example of that ? I think this will be very useful for a lot of users, since it's really hard to get a solution from the documentation.
Thanks in advance!
http://swfupload.org/forum/ge
http://swfupload.org/forum/generaldiscussion/457
I already read that one.. it
I already read that one.. it doesn't work...
Summaries Example
Here is a summarized example. Meaning that I didn't include every line of code just the "important" bits that are pertinent to what you are asking. This shows how easy it is to send extra data with a POST.
Note: You have to use the Flash 9 version (swfupload_f9.swf)
PSS: You can't just copy and paste this, it _will not work_. But understanding what this pseudo-code is doing will help you implement the concept in your own site.
index.php
<?php
$album_id = 100;
?>
<html>
<head>
<script>
var swfu;
window.onload = function () {
swfu = new SWFUpload({
post_params: {
album_id : "<?php echo $album_id; ?>" // Send this with all uploads
},
upload_start_handler : uploadStart
upload_success_handler: uploadSuccess
};
};
function uploadSuccess(file, server_data) {
// If there was an error show the message
if (server_data.substring(0, 4) === "Error") {
alert(server_data);
}
}
function uploadStart(file) {
// Add the album name to send specifically with this upload.
this.addFileParam(file.id, "album_name", document.getElementById("album_name").value);
return true;
}
</script>
</head>
<body>
<form>
<input type="hidden" id="album_id" value="<?php echo $album_id; ?>" />
<input type="text" id="album_name" value="" />
<button type="button" onclick="swfu.startUpload()">Upload Files</button>
</form>
</body>
</html>
upload.php
<?php
if (isset($_POST["album_id"]) && $_POST["album_id"] != "") {
$album_id = $_POST["album_id"];
} else {
echo "Error: No album id";
exit();
}
if (isset($_POST["album_name"]) && $_POST["album_name"] != "") {
$album_name = $_POST["album_name"];
} else {
echo "Error: No album name";
exit();
}
if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], "/var/uploads/".$_FILES[$upload_name]["name"])) {
echo "Error: Error saving file";
exit();
} else {
echo "Success: File uploaded: $album_id $album_name";
exit();
}
?>
When I use your example, it
When I use your example, it does work. But only for the first file. When I select e.g. 3 files, he only uploads the first file no problem, but he won't continue to the next one.
When I change the flash version to 8 he uploads perfectly again, but of course he won't send the POST vars... any idea where the problem might be ?
More info
Without more specific info on how you have your page setup it is almost impossible to help you.
The way SWFUpload works when you call startUpload it will begin uploading the first file in the queue if a file is not already uploading. Using the Flash 8 or Flash 9 version should not make a difference (but maybe there's a bug).
Ok, I'll show you what my
Ok, I'll show you what my problem is. I hope you have a bit of time to test it.
Surf to this URL : http://www.imagetime.nl/login/
The username and password I've send you with a private message.
After you've logged in, click on the button on the left "upload pictures".
In this screen you'll notice the upload tool. or surf to this url
URL : http://www.imagetime.nl/account/picture/add/
Just select a few files and then see what happens. The upload goes trough, when I check the database and my FTP, everything is executed, the file is uploaded, data is stored in the database, but he won't continue to the next file, that's the problem here.
I hope you can help me, it really would be a life saver.
Thanks in advance!
Server Data
I ran some uploads and uploadSuccess is never called. I did a packet sniff and your web server is returning a 200 status but is not return any data (or not enough data to convince flash to call uploadSuccess).
Your upload script must return some data in order for Flash to detect that the file has finished uploading.
That did the trick! Really
That did the trick!
Really THANKS A LOT !!!
For the people who want to
For the people who want to see a full working example.
You can find it at this url
URL : http://www.dev153.net/swfupload/
The files you can download here
URL : http://www.dev153.net/swfupload/SWF_Upload_POST.zip
I've put some comments, but just upload it on your hosting account, change the uploading paths and it should work.
The most important files are :
add_picture.php
add_picture_exe.php
handlers.js
I'll leave the example online for a week, don't upload to much photos please
:D
thanks
thanks imp4ct
doesn't upload all files
I'm using the version that was posted above, and it's not uploading all the files that I select. When I select 9 files, it will upload anywhere from 2-4 files. Its been changing, and with the exception of one file the rest of them differ each time. Is there a setting or something I'm missing here? I kept everything the same exept for the paths.
Thanks,
Jason
All files?
The files in the zip are the only files you need to upload to make it work? Cause when I click to upload no window pops up to select a file....
And is it possible to load them to an FTP server instead of the hostingserver. The FTP to my server is: http://195.18.64.39:8080... how can I implement that?
Thanks
Hi, Sorry for bringing this
Hi,
Sorry for bringing this back up, but I just cannot get SWFupload to send the posted details from the form attached to the file upload.
I can get the file to upload, and I can get the text input in my field to add to my database, but I cannot get them to work together. Something about the $_POST variable I am trying to pass between the swfupload part and the update.php file.
I have tried placing the variable in both the post_params and as this thread demoed within a separate function, but neither pass the details to the other page. I can transfer static data - that hasn't been inputted - but I need to move data/text entered by the visitor from the upload form to my database as well as showing the upload progress bar.
Thanks for any assistance.
Example
Here is an example of posted additional data with an upload.
http://demo.swfupload.org/test/index.php
(http://demo.swfupload.org/test/test.zip)
Take special note of the uploadStart function in handlers.js where the value from the textbox is read and added to the file's Post Params.
Then in upload.php I have it print out all the POST values sent which is received again by SWFUpload and made available in the uploadSuccess event (as the serverData parameter) and displayed on the web page.
Please download the zip file soon as this demo is temporary and could be removed/replaced at any time.
--------
It sounds like you might have been trying to do something different (like send post data separately as a normal Form Submit or Ajax call. Doing that would not involve SWFUpload (other than maybe trying to retrieve some kind of file/db identifier in the upload response) and you should be able to do it the same you would if you weren't using SWFUpload.
THANK YOU gyphie
You helped a lot, your example was very handy!
Example taken down? :(
I need to post some extra var's to my upload script, but the example is gone! anywhere I can still get it?
Any differences to the method with the new version?
Thanks in advance
Thanks, gyphie!
Thanks so much for your pseudo-code post from May 8, 2008. It has helped me tremendously!!
Example links are dead...
Hiya Gyphie... the example links you posted on September 15, 2008 seem to be dead. Any chance of pointing us in the right direction of those files again?
message uploading - no complete...
Hello gyphie,
this works fine.
But
1.:
There are 5 signs: Error
if (server_data.substring(0, 4) === "Error") {
This order musst call:
if (server_data.substring(0, 5) === "Error") {
2.:
When I have an error (the variable $k_mail is empty)
The alertmessage popup: "Error: Keine Mailaddr" comes up.
This is correct.
But when I set this variable, the file will be uploaded and the status obtain by:
Uploading...
Why comes no message complete?
When I deactivate the function uploadSuccess:
The message complete comes.
Best Regards
Udo Hillenbrand
upload.php:
if (isset($_POST["k_mail"]) && $_POST["k_mail"] != "") {
$k_mail = $_POST["k_mail"];
} else {
echo "Error: Keine Mailaddr $k_mail";
exit(0);
}
index.php:
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>",
"k_mail" : "<?php echo $k_mail; ?>"},
function uploadSuccess(file, server_data) {
// If there was an error show the message
if (server_data.substring(0, 5) === "Error") {
alert(server_data);
return true;
}
}
function uploadStart(file) {
// Add the album name to send specifically with this upload.
this.addFileParam(file.id, "k_mail", document.getElementById("k_mail").value);
return true;
}