Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tryin to upload an imagine in php

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
Hi there quick question want to upload an image into a directory suing windows XP home edition mySQL and apache in the usual fashion.

Im using the following script once the user has on a previous form chosen the file to upload.

<?
if ($userfile==&quot;none&quot;)
{
echo '<td class=form> Problem, no file uploaded </td>';
exit;
}

if ($userfile_size==0)
{
echo '<td class=form> Problem, uploaded file is of zero length </td>';
exit;
}

if (!is_uploaded_file($userfile))
{
echo '<td class=form> Problem, possible file upload attack </td>';
exit;
}


$upfile= &quot;$DOCUMENT_ROOT/php/agents/$valid_agent/&quot; . $userfile_name;

if( !copy($userfile, $upfile));
{
echo &quot;<td class=form>Problem: Could not move file into directory</td>&quot;;
exit;
}

echo &quot;<td class=form>File uploaded successfully<br><br></td>&quot;;
$fp = fopen($upfile, &quot;r&quot;);
$contents = fread ($fp, filesize($upfile));
fclose ($fp);

$contents = strip_tags($contents);
$fp = fopen($upfile, &quot;w&quot;);
fwrite($fp, $contents);
fclose($fp);

echo &quot;<tr><td class=form>Preview of uploaded file contents <br><hr></td></tr>&quot;;
echo $contents;
echo &quot;<td><br><hr></td>&quot;;
?>


The problem lies when this page is displayed it says that it hasnt uploaded the file e.g. it returns false when the if (!copy....) section of the script above.

thanks in advance

sanj


 
hi there wat happens is that it actually does let me upload but says that it hasnt uploaded it when i check the directory it is there uploaded in full...

does that help further could it be my logic in the if statement

thanks again
 
Insufficient data for a meaningful answer.

Where exactly in your code do you get the error?

What are the values in all the variables you are referencing? How did they get there? Does your code depend on register_globals to be set to &quot;on&quot; when it is not? Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top