Jump to content

Archived

This topic is now archived and is closed to further replies.

slipperyfish

Image Upload Problem

Recommended Posts

Well, im using this inconjunction with an AJAX script. Im passing the file location in the url, for example:

[CODE]
fileupload.php?loc=C:\files\file.txt
[/CODE]

Then letting this script take over, except it won't work?

[CODE]
<?php

if (isset($_GET['loc'])) {
$thetransfer = copy($_FILES[$_GET['loc']]['tmp_name'], 'uploads/'.$_FILES[$_GET['loc']]['name']);

If (!$thetransfer) {
echo 'Upload Failed!';
} else {
echo "File uploaded!";
}
}

?>
[/CODE]

Does anybody know why??

-Thanks

Share this post


Link to post
Share on other sites
YOu have to actually upload the file using a form with the proper enctype.  This is not easily done via AJAX...the only method I know of uses an iframe.  AJAX is javascript, which means that it is sandboxed and can not access the file system, so AJAX can not directly upload a file.

Share this post


Link to post
Share on other sites
I use move_uploaded_file() when I ever try to upload something to one of my webservers.

so
[code]
<?php
$filelocation = $_GET['loc'];
$newName = "MyNewFile";

if(move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/{$_FILES[$filelocation][$newname]'}) {
  // File moved
} else {
  // Error with moving file
}
?>
[/code]

Check to make sure your fileupload.php script also has the permission to execute and write to the directory you want to move the temp file into :)

$_FILE[] is from a submitted form that had a file linked to it from a users machine. 

Share this post


Link to post
Share on other sites
Here's a class from phpclasses.org that may help:

http://www.phpclasses.org/browse/package/2759.html

Share this post


Link to post
Share on other sites
i downloaded the script at that link you sent me, but im getting errors when i try to run it:

[QUOTE]
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in e:\domains\s\store02.newbiestyle.co.uk\user\htdocs\ajax-example3\dl\AjaxFileUploader.inc.php on line 16

Fatal error: Cannot instantiate non-existent class: ajaxfileuploader in e:\domains\s\store02.newbiestyle.co.uk\user\htdocs\ajax-example3\dl\index.php on line 15
[/QUOTE]

--------------------------------

is there actually a way of uploading/transferring/copying a file without using the $_FILES[] array?

-Thanks

Share this post


Link to post
Share on other sites
[quote]is there actually a way of uploading/transferring/copying a file without using the $_FILES[] array?[/quote]

No, not in php.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.