/    Sign up×
Community /Pin to ProfileBookmark

You are subscribed to this thread ajax upload file, filename passing problem in js?

Hi,

I’m amending an upload script from Max’s AJAX file uploader.
[url]http://www.ajaxf1.com/product/ajax-file-upload.html[/url]

I wish to display the filename after the file uploaded.

The text in green are added by myself. However, I failed to display success status after the upload process successful. Do you know where I made the error?

[QUOTE]

<!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>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Max’s AJAX File Uploader</title>
<link href=”style/style.css” rel=”stylesheet” type=”text/css” />

<script language=”javascript” type=”text/javascript”>
<!–
function startUpload(){
document.getElementById(‘f1_upload_process’).style.visibility = ‘visible’;
document.getElementById(‘f1_upload_form’).style.visibility = ‘hidden’;
return true;
}

function stopUpload(success[COLOR=”Green”],filename[/COLOR]){
var result = ”;
if (success == 1){
result = ‘<span class=”msg”>The file was uploaded successfully!</span><br/><br/>’;
}
else {
result = ‘<span class=”emsg”>There was an error during file upload!</span><br/><br/>’;
}
document.getElementById(‘f1_upload_process’).style.visibility = ‘hidden’;
document.getElementById(‘f1_upload_form’).innerHTML = result + ‘<label>File: <input name=”myfile” type=”file” size=”30″ /></label>[COLOR=”Green”]<label>Filename: <input name=”filename” type=”text” size=”30″ value=”‘+filename+'” readonly /></label>[/COLOR]<label><input type=”submit” name=”submitBtn” class=”sbtn” value=”Upload” /></label>’;
document.getElementById(‘f1_upload_form’).style.visibility = ‘visible’;
return true;
}
//–>
</script>
</head>

<body>
<div id=”container”>
<div id=”header”><div id=”header_left”></div>
<div id=”header_main”>Max’s AJAX File Uploader</div><div id=”header_right”></div></div>
<div id=”content”>
<form action=”upload.php” method=”post” enctype=”multipart/form-data” target=”upload_target” onsubmit=”startUpload();” >
<p id=”f1_upload_process”>Loading…<br/><img src=”loader.gif” /><br/></p>
<p id=”f1_upload_form” align=”center”><br/>
<label>File:
<input name=”myfile” type=”file” size=”30″ />
</label>
<label>
<input type=”submit” name=”submitBtn” class=”sbtn” value=”Upload” />
</label>
</p>

<iframe id=”upload_target” name=”upload_target” src=”#” style=”width:0;height:0;border:0px solid #fff;”></iframe>
</form>
</div>
<div id=”footer”><a href=”http://www.ajaxf1.com” target=”_blank”>Powered by AJAX F1</a></div>
</div>

</body>

[/QUOTE]

[QUOTE]

<?php
// Edit upload location here
$destination_path = getcwd().DIRECTORY_SEPARATOR;

$result = 0;

[COLOR=”Green”]$path_parts = pathinfo($_FILES[‘myfile’][‘name’]);
$the_image_type=$path_parts[‘extension’];

$filename=$now.”.”.$the_image_type;[/COLOR]

$target_path = $destination_path . basename( $_FILES[‘myfile’][‘name’]);

if(@move_uploaded_file($_FILES[‘myfile’][‘tmp_name’], $target_path)) {
$result = 1;
}

sleep(1);
?>

<script language=”javascript” type=”text/javascript”>window.top.window.stopUpload(<?php echo $result; ?>[COLOR=”Green”],<?php echo $filename; ?>[/COLOR]);</script>

[/QUOTE]

It seems that the problem is caused somewhere at:

[QUOTE]

stopUpload(success[COLOR=”Green”],filename[/COLOR])
.
.
.
.
.
<script language=”javascript” type=”text/javascript”>window.top.window.stopUpload(<?php echo $result; ?>[COLOR=”Green”],<?php echo $filename; ?>[/COLOR]);</script>

[/QUOTE]

When I removed the text marked in green, the ajax upload working well again.

But from my experience, it should be fine passing the value like that, right?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @janejane spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...