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
https://forums.phpfreaks.com/topic/59062-solved-upload/
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
https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293181
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
https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293221
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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