sintax63 Posted January 7, 2010 Share Posted January 7, 2010 Hello PHP Freaks - I have come across a problem with a web app I'm writing and was hoping to get some assistance. I have a form which is used to upload a photo (see below). I have used it before on one site without any problems. This time however, I need to have the form / web page on "domain.com" and the file upload to a directory in "sub.domain.com". I keep getting the following error: Warning: move_uploaded_file(http://sub.domain.com/main/photos/1.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/user/public_html/sandbox/photos.php on line 102 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpteSwWs' to 'http://sub.domain.com/main/photos/1.jpg' in /home/user/public_html/sandbox/photos.php on line 102 Line 102 contain the following: if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) { And the entire PHP code for the upload script is as follows: // ------------------------------------------------ // Checks To See If A Photo Is Being Uploaded... // ------------------------------------------------ if(isset($_REQUEST['submit'])) { $next = $id; // ------------------------------------------------ // Separates The File Name From The Extension // ------------------------------------------------ function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } // ------------------------------------------------ // Applies The Function To The File // ------------------------------------------------ $ext = findexts ($_FILES['userfile']['name']) ; // ------------------------------------------------ // Renames The File To Match The Entry ID // ------------------------------------------------ $pic = $next."."; // ------------------------------------------------ // Define The Photo Upload Directory // ------------------------------------------------ $target = "http://sub.domain.com/main/photos/"; // ------------------------------------------------ // Creates The Directory/Name.Extenstion // ------------------------------------------------ $target = $target . $pic.$ext; if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) { header( "Location: photos.php" ); } else { echo "Something Went Wrong... <br />"; } } Any help would be greatly appreciated as I'm coming up on my deadline. Thanks! Link to comment https://forums.phpfreaks.com/topic/187613-uploading-a-file-from-my-main-domain-to-a-sub-domain/ Share on other sites More sharing options...
ignace Posted January 7, 2010 Share Posted January 7, 2010 I already told you that: $ext = findexts ($_FILES['userfile']['name']) ; // is the same as $ext = pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION); You don't need to waste more memory then required. If you want to upload a file from domain.com to sub.domain.com then place the upload script on sub.domain.com and let domain.com refer to it <form action="http://sub.domain.com/upload.php"> Or if you need it at both domains perform the upload on domain.com and then pass (using curl) a task to sub.domain.com which tells him that he needs to download a file something like: http://sub.domain.com/upload.php?uri=http://domain.com/uploads/file.jpg Link to comment https://forums.phpfreaks.com/topic/187613-uploading-a-file-from-my-main-domain-to-a-sub-domain/#findComment-990520 Share on other sites More sharing options...
sintax63 Posted January 7, 2010 Author Share Posted January 7, 2010 Hello ignace - You did and I must have missed it. Sorry about that... While you were replying to my first post I went ahead and moved the upload portion of the script over to my subdomain, however I am getting the same error about "writable connections". I must be missing something but I'll keep messing with it. Thanks again! Link to comment https://forums.phpfreaks.com/topic/187613-uploading-a-file-from-my-main-domain-to-a-sub-domain/#findComment-990535 Share on other sites More sharing options...
sintax63 Posted January 7, 2010 Author Share Posted January 7, 2010 GOT IT! Thanks for the help ignace! Link to comment https://forums.phpfreaks.com/topic/187613-uploading-a-file-from-my-main-domain-to-a-sub-domain/#findComment-990539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.