# [web] Almost done with tumbnail upload on my website but I still have a small problem.

## Recommended Posts

SteveDeFacto    109
So far what I've got is a window that pops up then the user selects the image to upload and presses the upload button, it uploads the image and is suppose to display it on the opener window but thats where I'm having problems, here is my source:
<?php
include 'random_string.php';
include 'file_extension.php';
$rand = randomString(10);$target_path = "uploads/" . $rand .".". fileExtension($_FILES['file']['name'] );
if(move_uploaded_file($_FILES['file']['tmp_name'],$target_path))
{
echo('<script language = "JavaScript">');
echo('if (window.opener && !window.opener.closed)');
echo('{');
echo('var temp = new Image();');
echo('temp.src = "'.\$target_path.'";');
echo('window.opener.document["thumbnail").src = temp.src;');
echo('}');
echo('window.close();');
echo('</script>');
}
else
{
}
?>



##### Share on other sites
Not sure about the answer to your problem but I'd be very careful about letting people upload files without you validating them to some extent. Someone could upload a c99 script (google it if you don't know what it is) and have total control. If you let them specify the place to upload it too, a hacker could choose index.html and your index file is deleted for the hackers version!
Be careful...

##### Share on other sites
Palidine    1315
What's the problem you're having? What does move_uploaded_file do?

It looks like you're trying to upload a file to your server? I'm not sure what you're trying to do. You're running some code in javascript, but that's all client side stuff it looks like...

So yeah, not really sure what you're trying to do.

-me

##### Share on other sites
SteveDeFacto    109
Quote:
 Original post by PalidineWhat's the problem you're having? What does move_uploaded_file do?It looks like you're trying to upload a file to your server? I'm not sure what you're trying to do. You're running some code in javascript, but that's all client side stuff it looks like...So yeah, not really sure what you're trying to do.-me

Yes I think the javascript is the problem, mainly this code that should display the image on the main window but it just crashes, let me break it down to display the problem more clearly:

var temp = new Image();
temp.src = "image path";
window.opener.document["thumbnail").src = temp.src;

From a tutorial I read about updating images that should be the way to do it... I think...