Jump to content


Photo

Image Upload Problem


  • Please log in to reply
6 replies to this topic

#1 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 20 August 2006 - 08:16 PM

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

fileupload.php?loc=C:\files\file.txt

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

<?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!";
	}
}

?>

Does anybody know why??

-Thanks

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 08:18 PM

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.

#3 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 20 August 2006 - 08:21 PM

I use move_uploaded_file() when I ever try to upload something to one of my webservers.

so
<?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
}
?>

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. 

#4 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 20 August 2006 - 08:25 PM

I see, I see. Is it possibile to upload a file without using the $_FORMS variable?

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 08:34 PM

Here's a class from phpclasses.org that may help:

http://www.phpclasse...ckage/2759.html

#6 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 20 August 2006 - 08:55 PM

i downloaded the script at that link you sent me, but im getting errors when i try to run it:

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


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

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

-Thanks

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 11:34 PM

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


No, not in php.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users