424,294 Members | 1,898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,294 IT Pros & Developers. It's quick & easy.

Upload File

P: n/a
Dev
Dear All,

I want to upload a file with PHP script. For that i use code given
below. with this code my operation success but there is no file on my
Server/Website
Anyone help me to solve this problem.
Thanks in Advance
Dev

Code for HTML Page

<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>

code for upload.php Page

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] 0)
{ echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{ echo $_FILES["file"]["name"] . " already exists. "; }
else
{ move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" .
$_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{ echo "Invalid file"; }
?>

Output of the action:

Upload: splendor.jpg
Type: image/pjpeg
Size: 160.4287109375 Kb
Temp file: /tmp/php1DU5Tq
Stored in: upload/splendor.jpg
Dec 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dev wrote:
Dear All,

I want to upload a file with PHP script. For that i use code given
below. with this code my operation success but there is no file on my
Server/Website
Anyone help me to solve this problem.
Thanks in Advance
Dev
This will store the file in the "upload" directory *relative to the
current script's path*. Does this directory exist, and is it writable
by the web server user? What's the return value from move_uploaded_file()?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Dec 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.