Is there a way to control what file extensions the end-users are permitted to upload,
before uploading files with New 3.5 dhtmlxForm Multiple File Uploader
Hi
currently form does not provide such functionality.
may it will added later.
Are there any examples on the server side (PHP) for doing this? Here’s what I’ve added:
if (@$_REQUEST["mode"] == "html5" || @$_REQUEST["mode"] == "flash") {
$filename = $_FILES["file"]["name"];
if ($_FILES['fileload']['type'] != "image/x-png"){
print_r("{state: fail, name:'".str_replace("'","\\'",$filename)."'}");
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],"/data/".$filename);
print_r("{state: true, name:'".str_replace("'","\\'",$filename)."'}");
}
}
Can I tell the uploader control of failure like this? It doesn’t appear to be doing anything.
please provide completed demo (see details in a topmost post in this forum)
Andrei,
What I gave is pretty much everything. Here’s the form…not much more than the sample:
[code]var strUpload = [
{ type:“upload” , name:“formUpload_uploader”, label:“Select files for upload”, inputWidth:400, inputHeight:100, url:“include/messenging/dhtmlxform_item_upload.php”, swfPath:“script/codebase35/ext/uploader.swf”, swfUrl:“include/messenging/dhtmlxform_item_upload.php” }
];
var formUpload = popupWindow.attachForm(strUpload);[/code]
And here’s the server side PHP script:
[code]<?php
/*
HTML5/FLASH MODE
(MODE will detected on client side automaticaly. Working mode will passed to server as GET param “mode”)
response format
if upload was good, you need to specify state=true and name - will passed in form.send() as serverName param
{state: ‘true’, name: ‘filename’}
*/
if (@$_REQUEST[“mode”] == “html5” || @$_REQUEST[“mode”] == “flash”) {
$filename = $_FILES[“file”][“name”];
if ($_FILES[‘fileload’][‘type’] != “image/x-png”){
print_r("{state: fail, name:’".str_replace("’","\’",$filename)."’}");
} else {
move_uploaded_file($_FILES[“file”][“tmp_name”],"/data/overlay/emergency/".$filename);
print_r("{state: true, name:’".str_replace("’","\’",$filename)."’}");
}
}
/*
HTML4 MODE
response format:
to cancel uploading
{state: ‘cancelled’}
if upload was good, you need to specify state=true, name - will passed in form.send() as serverName param, size - filesize to update in list
{state: ‘true’, name: ‘filename’, size: 1234}
*/
if (@$_REQUEST[“mode”] == “html4”) {
if (@$_REQUEST[“action”] == “cancel”) {
print_r("{state:‘cancelled’}");
} else {
$filename = $_FILES[“file”][“name”];
move_uploaded_file($_FILES[“file”][“tmp_name”], “/data/overlay/emergency/”.$filename);
print_r("{state: true, name:’".str_replace("’","\’",$filename)."’, size:".$_FILES[“file”][“size”]/filesize(“uploaded/”.$filename)/."}");
}
}
?>[/code]
All I did was change the HTML5/FLASH part to check the mime type of the uploaded file, but now what? I’m printing a failed state, but it doesnt change the uploader form control, nor does it seem to fire the following onUploadFail event handler:
formUpload.attachEvent("onUploadFail",function(realName){
alert(realName)
});
Andrei,
Let me know if you need more than that. I’m running a freshly download copy of the library so I didn’t think I needed to include it.
Thanks!
Hi
print_r("{state: fail, name:’".str_replace("’","\’",$filename)."’}");
this will not parsed correctly, add quotes “fail” of use false
under completed demo I mean all js/css/php files,
to open your demo localy and check
Attached is my source. I think the problem is a little deeper that originally described. I now do not believe that the uploader control is allowing dhtmlxform_item_upload.php to process the upload. It might just be a path issue, but nothing I try seems to be working. Please tell me what is going wrong. I’ve stripped the custom PHP code in this file that I was using to attempt to only allow files of a certain type as described in the forum thread.
dhtmlx_uploader_help.zip (787 KB)
hi
your demo works fine localy
any chance to see demo on your side?
(if you don’t want share info here you can send it to support@dhtmlx.com, please include link to this thread)