Manoj Manoj - 2 days ago 3
PHP Question

Upload image file using href in move_uploaded_file( ) php

I need some advice and guide line.
I am trying to upload image into a folder using link. And I am unable to upload an image.
I am trying this code. This shows error message :


[function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections


<?php

if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{

if (file_exists("http://localhost.myimage.com/uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"http://localhost.myimage.com/uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}

?>
<html>
<body>

<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>


Is it possible ?

Answer

The destination of the moved file needs to be an absolute path to the server, i.e.

move_uploaded_file( $_FILES["file"]["tmp_name"], $_SERVER['DOCUMENT_ROOT'] ."/uploads/" . $_FILES["file"]["name"]);