DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Uploading with PHP error (http://www.daniweb.com/forums/thread130044.html)

mesamb1 Jun 18th, 2008 10:08 pm
Uploading with PHP error
 
I am trying to write a simple php program that will up load files smaller then 200000000 bytes to my website, but I keep getting an error when I try to run it
the initial HTML code is:
    <html>
<body>

<form action="upload.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>

and then the following is the php code:

[code]
<?php
if (($_FILES["file"]["size"] < 200000000))
{
if ($FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"] ["error"] . "<br />";
}
else
{
$Size = ($_FILES["files"]["size"]/ 1024);
if ($Size > 1000)
{
$Size= $Size/1000;
$type = "Mb";
}
else
{
$type= "Kb";
}

echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . $Size . " " . $type . "<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("stuff/" . $_FILES["file"] ["name"] ))
{
echo $_FILES["file"]["name"] . " already exist. ";
}
else
{


move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "stuff/" . $_FILES["file"] ["name"];
}
}
}
else
{
header("Location: http://www.doled.org/upload/uhuh.html");
}
?>
[\code]

which when I run on line gives me the error
"Upload: balloon08.gif
Type: image/gif
Size: 0 Kb
Temp file: /usr/local/tmp/phpe96Gqh

Warning: move_uploaded_file(upload/balloon08.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/.aspen/mesamb1/doled.org/upload/upload.php on line 32

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/usr/local/tmp/phpe96Gqh' to 'upload/balloon08.gif' in /home/.aspen/mesamb1/doled.org/upload/upload.php on line 32
Stored in: stuff/balloon08.gif"

which makes no since to me and I would like to fix, any advice would be greatly appreciated

khess Jun 19th, 2008 5:26 pm
Re: Uploading with PHP error
 
You need to look in your php.ini file and make sure you have a writeable directory for uploads. It is a temp directory for uploads to the server. On Linux, it is usually /tmp but can be almost anywhere that the web server has write access.

Change the php.ini and restart the web server.

mesamb1 Jun 20th, 2008 5:28 pm
Re: Uploading with PHP error
 
I changed the name of the place on my server where I wanted the file to go and that seems to have done the trick, thanks for your help khess


All times are GMT -4. The time now is 10:23 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC