Jump to content

[SOLVED] Upload


Asday

Recommended Posts

I have this code:

 

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error:  " . $FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload:  " . $_FILES["file"]["name"] . "<br />";
echo "Type:  " . $_FILES["file"]["type"] . "<br />";
echo "Size:  " . (($_FILES["file"]["size"] / 1024) / 1024) . "MB<br />";
echo "Stored in:  " . $_FILES["file"]["tmp_name"] . "<br /><br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
	echo $_FILES["file"]["name"] . " already exists, foof!";
}
else
{
	move_uploaded_file($_FILES["name"]["tmp_name"],
	"/upload/" . $_FILES["file"]["name"]);
	echo 'It`s now <a href="/upload/' . $_FILES["file"]["name"] . '">here.</a>  Tell your friends!';
}
}
?>

 

Which doesn't work.  When I click the "here", it pulls out a 404.  The file doesn't even upload to the specified location, becuase the folder remains empty.

 

(On another page, there is a form with the necessary things to upload a file:  Textbox, browse button, submit button...)

 

Thanks.

Link to comment
Share on other sites

move_uploaded_file($_FILES["name"]["tmp_name"]

 

Here is the problem,

 

You use different variable name: 'name' instead of 'file'

 

 

--

Tapos Pal

 

Now I get this:

 

Warning: move_uploaded_file(/upload/1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\uploadFile.php on line 20

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php67.tmp' to '/upload/1.jpg' in C:\xampp\htdocs\uploadFile.php on line 20

 

Am I using the wrong slashes?

Link to comment
Share on other sites

Well, Matto helped a little, but I solved it myself.  Thanks for trying, guys.

 

Final code:

 

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error:  " . $FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload:  " . $_FILES["file"]["name"] . "<br />";
echo "Type:  " . $_FILES["file"]["type"] . "<br />";
echo "Size:  " . (($_FILES["file"]["size"] / 1024) / 1024) . "MB<br />";
echo "Stored in:  " . $_FILES["file"]["tmp_name"] . "<br /><br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
	echo $_FILES["file"]["name"] . " already exists, foof!";
}
else
{
	move_uploaded_file($_FILES["file"]["tmp_name"],
	"upload/" . $_FILES["file"]["name"]);
	echo 'It`s now <a href="/upload/' . $_FILES["file"]["name"] . '">here.</a>  Tell your friends!';
}
}
?>

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.