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! Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.