<?php
//set where you want to store files
//in this example we keep file in folder upload 
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "/home/content/a/b/a/abazoskib/html/snapit/photos/".$_FILES['ufile']['name'];
if($ufile !=none)
{
if(copy($_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>"; 

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$_FILES['ufile']['name']."<BR/>"; 
echo "File Size :".$_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_file.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file 
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

it won't work! i tried even just "photos/" for the path and nothing. $_FILES is always empty and I always get an error. My goal is to just have an image uploader, however I cannot upload anything through this form.

photos is set to 777 permission

What error do you get ?
And what do you have this for ?

if($ufile !=none)
{
......
}

This works for me :)

<?php
//set where you want to store files
//in this example we keep file in folder upload 
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "./images/".$_FILES['ufile']['name'];
if(isset($_POST['Submit']))
{
if(copy($_FILES['ufile']['tmp_name'], $path)) 
{
echo "Successful<BR/>"; 

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$_FILES['ufile']['name']."<BR/>"; 
echo "File Size :".$_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>

<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_file.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file 
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

that code outputs "Error" for me. Could it be godaddy configuration?

register_globals = off

allow_url_fopen = off

file_uploads = on


expose_php = Off

max_input_time = 60

variables_order = "EGPCS"

extension_dir = ./
upload_tmp_dir = /tmp
precision = 12
SMTP = relay-hosting.secureserver.net
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

[Zend]
zend_extension=/usr/local/zo/ZendExtensionManager.so
zend_extension=/usr/local/zo/4_3/ZendOptimizer.so

that is in my php.ini file

:-/ Nothing wrong. Print $_FILES['ufile']['error'] . Check if tmp and /home/content/a/b/a/abazoskib/html/snapit/photos/ has the privileges.

[abazoskib@p3nlh053 ~]$ ls -ld /tmp
drwxrwxrwt 107 0 0 1609728 Apr 29 19:52 /tmp

photos/ was set to 777 through ftp

echo $_FILES; ... does not output anything

i got it. its for a facebook app so the action has to have an explicit url not a relative path to the upload_file.php script

This article has been dead for over six months. Start a new discussion instead.