Jump to content

Uploading A File From My Main Domain To A Sub-Domain


sintax63

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.