Link to home
Start Free TrialLog in
Avatar of trican
trican

asked on

File Upload

Hi,
Simple question, I'm trying to do a file upload and I'm having problems

upload.html
.
.
<form action="upload.php" method="post" enctype="multipart/form-data">
      <p>Select File to upload:
      <input type="file" name="uploadfile" /></p>
      
      <p><input type="submit" name="Submit" value="Submit" /></p>
</form>
.
.

upload.php
<?
//file extension check
if (eregi('^image/p?jpeg(;.*)?$', $_FILES['uploadedfile']['type']))
      $extension = '.jpg';
else $extension = '.gif';      
echo $extension;

$filename = $_SERVER['DOCUMENT_ROOT'].'/temp00001'. $extension;

if (copy($_FILES['uploadedfile']['tmp_name'], $filename))
{
      echo "<p>file stored successfully as $filename</p>";
}
else
{
            echo "<p>Problem with file storage</p>";
}            
?>

It always reports the "Problem with file storage" also the gif is always returned from the extension check.

Any help appreciated
ASKER CERTIFIED SOLUTION
Avatar of pjdietz
pjdietz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trican
trican

ASKER

that directory i'm trying to upload to is 755 and directory above that is 750 .. but i persume this is fine.

The first part is making sure the graphic file is what it claims it is by examining the $_FILES['uploadedfile']['type'].


I made the upload.php file really basic having just the following:

$filename = $_SERVER['DOCUMENT_ROOT'].'/pics/temp00001.jpg';
if (copy($_FILES['uploadedfile'], $filename))
{
      echo "<p>file stored successfully as $filename</p>";
}
else
{
            echo "<p>Problem with file storage</p>";
}


but the else condition always executes? :-(