Solved

File Upload

Posted on 2003-11-26
2
683 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now