<script type= "text/javascript">
/*<![CDATA[*/
$(document).ready(function(){
$('form.upform').submit(function() {
$(".file").animate({"height": "toggle", "opacity": "toggle"}, "slow");
$(".loading").fadeIn("slow");
});
});
var max = <?=$settings['SET_MAX_UPLOAD'];?>;
var count = 1;
$(document).ready(function(){
$('.add_another_file_input').click(function(){
var html = $('.Upload_Multiple').prev('.input').html();
$('.file:last').after( '<div class="input file hide">'+html+'</div>' );
$('.file:last').animate({"height": "toggle", "opacity": "toggle"}, "slow");
count++;
if(count >= max) $('.Upload_Multiple').animate({"height": 0, "opacity": 0}, "slow");
if(count === 2) copyfileName();
return false;
});
});
$(document).ready(function(){
$("#linkremote").click(function(){
$('#local_panel').fadeOut(1);
$('.Upload_Multiple').animate({"height": 0, "opacity": 0}, "slow");
$('div.hide').animate({"height": "toggle", "opacity": "toggle"}, "slow").delay(800).remove(".hide");
count = 1;
$('#remote_panel').delay(2).fadeIn("slow");
$('#linklocal').removeClass('linklocal show').addClass('linklocal');
$('#linkremote').removeClass('linkremote').addClass('linkremote show');
});
$("#linklocal").click(function(){
$('#remote_panel').fadeOut(1);
if(count < max) $('.Upload_Multiple').delay(1).animate({"height": '20px', "opacity": "100"}, "slow");
$('#local_panel').delay(2).fadeIn("slow");
$('#linklocal').removeClass('linklocal').addClass('linklocal show');
$('#linkremote').removeClass('linkremote show').addClass('linkremote');
});
});
function copyfileName() {
var name;
var file = document.upload.elements["file[]"];
var file_name = document.upload.elements["fileName[]"];
var alt = document.upload.elements["alt[]"];
if (file.length > 0){
for (i = 0; (i < file.length); i++) {
if (file_name[i].value != file[i].value){
file_name[i].value = file[i].value;
name = file_name[i].value.slice(file_name[i].value.lastIndexOf("\\")+1,file_name[i].value.lastIndexOf('.'));
alt[i].value = name.replace(/_|-/g," ");
}
}
}else{
file_name.value = file.value;
name = file_name.value.slice(file_name.value.lastIndexOf("\\")+1,file_name.value.lastIndexOf('.'));
alt.value = name.replace(/_|-/g," ");
}
}
function fileExt() {
var extArray = new Array("<?=implode('","',$accepted);?>");
var file = document.upload.elements["fileName[]"];
for (i = 0; (i < file.length); i++) {
var extOk = false;
if (!file[i].value) return false;
var filename = file[i].value.slice(file[i].value.indexOf("\\") + 1);
var ext = filename.slice(-3).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] === ext) {
extOk = true;
}
}
if (extOk != true) {
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
return false;
}
}
return true;
}
/*]]>*/
</script>
<form enctype="multipart/form-data" action="../imagehost/upload.php" method="post" class="upform" name="upload" id="upload">
<input type="text" id="fileName" name="fileName[]" class="text_input long" readonly="readonly" />
<input type="file" name="file[]" id="file" class="file_input_hidden" onchange="javascript: copyfileName()" />
<label for="alt" class="des">Description: (optional)</label>
<input type="text" name="alt[]" id="alt" class="text_input long_des" /></div>
<input name="submit" type="submit" value="Upload" class="button" onclick="return fileExt()" /></form>
<?
function scandirt($dir){
$items = glob($dir . '/*.jpg');
for ($i = 0; $i < count($items); $i++) {
if (is_dir($items[$i])) {
$add = glob($items[$i] . '/*');
$items = array_merge($items, $add);} }
return $items;}
$dir = '/var/www/skim/skimmed/';
$file = scandirt($dir);
$pictures = array();
foreach($file as $path => $pic) {
$pictures[$path] = end(explode('/',$pic));}
foreach ($pictures as $picture){
$alt = ltrim(str_replace($num, ' ', $picture));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, 'http://diabolical-fs/curl/imageh.php' );
$post_array = array(
"file[]"=>"@".$dir. $picture,
"alt[]" => $alt,
"submit"=> "Upload",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo "Erro CURL: " . curl_error($ch);
}
echo $response;}
?>
Above is the handler which gets the filename and pulls the extension etc from it to pass to the uploader. Using this same curl I was able to post to 3 other mockups which do not use javascript onclick, onchange functions what am i missing to make this work ? Sending the data directly to the upload handler i get errors such as file not supported or not right kind of type etc. This is of course because the java is handling getting extensions etc. But when i pass it to the actual form I get no errors. no nothing it is almost as if it runs correct except it does not populate the upload at all.