slipperyfish Posted August 20, 2006 Share Posted August 20, 2006 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 https://forums.phpfreaks.com/topic/18130-image-upload-problem/ Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 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 https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77718 Share on other sites More sharing options...
SharkBait Posted August 20, 2006 Share Posted August 20, 2006 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 https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77720 Share on other sites More sharing options...
slipperyfish Posted August 20, 2006 Author Share Posted August 20, 2006 I see, I see. Is it possibile to upload a file without using the $_FORMS variable? Link to comment https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77726 Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 Here's a class from phpclasses.org that may help:http://www.phpclasses.org/browse/package/2759.html Link to comment https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77729 Share on other sites More sharing options...
slipperyfish Posted August 20, 2006 Author Share Posted August 20, 2006 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 16Fatal 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 https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77734 Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 [quote]is there actually a way of uploading/transferring/copying a file without using the $_FILES[] array?[/quote]No, not in php. Link to comment https://forums.phpfreaks.com/topic/18130-image-upload-problem/#findComment-77785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.