Solved

File Upload

Posted on 2003-11-26
2
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 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…

749 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