Forum Moderators: coopster

Message Too Old, No Replies

Page Refresh Image Upload Help

php, image, ajax, xmlhttprequest

         

confused noob

3:54 am on Jul 3, 2008 (gmt 0)

10+ Year Member



Hello all!

what is wrong with my code?

<?php>
echo ($HTTP_POST_FILES['thefile']['name']);
$file_realname = trim($HTTP_POST_FILES['thefile']['name']);
$uploaddir = "/images/";

if (move_uploaded_file($HTTP_POST_FILES['thefile']['tmp_name'], $uploaddir . $file_realname)) {
} else {
print "<strong>$file_realname</strong> did not upload!";
}
?>

The code above is called from a ASP page but I seem to lose the file in translation. What am I doing wrong. Why won't the code upload the image from an ASP form?

Also, is it possible to follow this path: ASP(FORM) -> JS(XMLHTTPREQUEST) -> PHP(UPLOAD FUNCTION)

I am attempting to refresh part of the page.

Thanks for you help.

eelixduppy

4:37 am on Jul 3, 2008 (gmt 0)



Welcome to WebmasterWorld!

Try the following, first, and see what it gives you. Put this at the top of this script:


echo '<pre>'; print_r($_FILES); echo '</pre>';
exit;

confused noob

4:44 am on Jul 3, 2008 (gmt 0)

10+ Year Member



This is what it gave me:

Array
(
[thefile] => Array
(
[name] => SN151380.JPG
[type] =>
[tmp_name] =>
[error] => 2
[size] => 0
)

)

eelixduppy

4:50 am on Jul 3, 2008 (gmt 0)



You are getting an error 2 which means "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form."

You must upload a smaller file or increase the max_file_size in the form.

confused noob

5:12 am on Jul 3, 2008 (gmt 0)

10+ Year Member



Ok, as of right now, this is what I have set for the max_file_size = 150000. The file I am uploading is only 940kb.

<input type=hidden name=MAX_FILE_SIZE value=150000>

I am changing the attributes and testing...brb

confused noob

5:30 am on Jul 3, 2008 (gmt 0)

10+ Year Member



This is the js function within the asp page that calls the php page.

function updateImg(action, uID, param1)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var filename = document.form1.whatsit.value;//Image Name

alert (filename);
var url="test.php"
url=url+"?action="+action
url=url+"&username="+uID
url=url+"&param1="+param1
//url=url+"&param2="+param2
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

when I run this script, with the code you gave me, it get the following:

Array
(
)

Is this not possible? To go from Embedded JS in ASP to PHP.

eelixduppy

2:21 pm on Jul 3, 2008 (gmt 0)



It is certainly possible to achieve this asynchronous upload. You will probably have better help in the Javascript/AJAX [webmasterworld.com] forum, though, as the javascript may get a little more complicated.

confused noob

4:22 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



I will try that...thanks for you help...I am 85% there..