Solved

File Upload

Posted on 2003-11-26
2
686 Views
Last Modified: 2009-07-29
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
0
Comment
Question by:trican
2 Comments
 
LVL 1

Accepted Solution

by:
pjdietz earned 45 total points
ID: 9826762
A few thoughts,

First, make sure that the folder you are trying to copy the file into is write-enabled.

Second, I don't think you need to use the tmp_name. I think you can just use $_FILES['uploadedfile']['filename'].

As for the regular expression, if you are trying to search for literal paranthesis, I think you need to escape them (i.e., ...jpeg\(;.*\)?...), otherwise, you're using the syntax for a stored group. Since I don't see you back referencing anywhere, I'm assuming you want to actually find the characters ( and ).
0
 
LVL 1

Author Comment

by:trican
ID: 9830834
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? :-(
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question