File upload directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

File upload directory

Post by jauson »

Helo Guys! Hi I keep receiving this error.. can someone explain to me why this happen?
==========================

Upload: 165343_1803646733550_1311313795_2080049_5276461_n.jpg
Type: image/jpeg
Size: 84.056640625 Kb
Stored in: C:\xampp\tmp\php2E50.tmp
Warning: move_uploaded_file(C://xamp/htdocs/Lacson_exam/files/165343_1803646733550_1311313795_2080049_5276461_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\exercise\upload_file.php on line 20

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php2E50.tmp' to 'C://xamp/htdocs/Lacson_exam/files/165343_1803646733550_1311313795_2080049_5276461_n.jpg' in C:\xampp\htdocs\exercise\upload_file.php on line 20
Stored in: C://xamp/htdocs/Lacson_exam/files/165343_1803646733550_1311313795_2080049_5276461_n.jpgInvalid file
======================================================================================================

heres my script.

<?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) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
if (file_exists("C://xamp/htdocs/Lacson_exam/files/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"C://xamp/htdocs/Lacson_exam/files/" . $_FILES["file"]["name"]);
echo "Stored in: " . "C://xamp/htdocs/Lacson_exam/files/" . $_FILES["file"]["name"];

}
echo "Invalid file";
?>
Zephni
Forum Newbie
Posts: 8
Joined: Fri Oct 07, 2011 1:59 pm

Re: File upload directory

Post by Zephni »

Can you post your form aswell?
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Re: File upload directory

Post by jauson »

heres my form..

<html>
<body>

<form action="upload_file.php" 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>
yassinebelkaid
Forum Newbie
Posts: 1
Joined: Sat Oct 08, 2011 2:54 pm

Re: File upload directory

Post by yassinebelkaid »

Hi Jauson, I think instead of writing : move_uploaded_file($_FILES["file"]["tmp_name"],
"C://xamp/htdocs/Lacson_exam/files/" . $_FILES["file"]["name"]);
simply create a variable called $path = "Lacson_exam/files/" .$_FILES["file"]["name"]";
and replace "C://xamp/htdocs/Lacson_exam/files/" . $_FILES["file"]["name"]); by $path.

Hope you the best!
Post Reply