Jump to content

Image Upload Problem


slipperyfish

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
Link to comment
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.
Link to comment
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. 
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.