Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,126 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,777 people online right now. Registration is fast and FREE... Join Now!




uploading an image to a server

 
Reply to this topicStart new topic

uploading an image to a server, how a user can upload an image to my server, to a specific folder

psydoll
27 Feb, 2007 - 01:54 AM
Post #1

New D.I.C Head
*

Joined: 22 Feb, 2007
Posts: 8


My Contributions
I have set it up for jpeg files only right now. what im trying to get this code to do is allow the user to upload jpegs, gifs, bitmaps to a specific folder on my server called applicantsImages. I am thinking the most logical way to get jpegs as well as gifs and bitmaps would be to use cases as I saw in others code, but I am a little unsure how to change what i have which is if statements to cases. also im not sure how to designate the server folder they will end up in. Right now the site when run on the remote server keeps telling me: "Could not copy" , here is the php code i have created thus far:


CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/jpeg"){
    copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
    or die ("Could not copy");
    echo "";
        echo "Name: ".$_FILES['imagefile']['name']."";
        echo "Size: ".$_FILES['imagefile']['size']."";
        echo "Type: ".$_FILES['imagefile']['type']."";
        echo "Copy Done....";
      }
      
     else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
}     
    ?> </form>
</body>
</html>


[mod edit]Use the code tags!
User is offlineProfile CardPM
+Quote Post

snoj
RE: Uploading An Image To A Server
27 Feb, 2007 - 06:13 AM
Post #2

$Null
Group Icon

Joined: 31 Mar, 2003
Posts: 3,304



Thanked: 6 times
Dream Kudos: 700
My Contributions
First off you should change $Submit to $_POST['Submit'] as register globals is never a good way to code.

The problem is likely in that you don't have the proper permissions for the destination folder.
User is offlineProfile CardPM
+Quote Post

Xmod
RE: Uploading An Image To A Server
28 Feb, 2007 - 02:06 PM
Post #3

New D.I.C Head
*

Joined: 19 Jan, 2007
Posts: 35


My Contributions
look at this example

CODE

if(isset($_POST[s1]))
{
    if(!empty($_FILES[images][name][0]))
    {
        while(list($key,$value) = each($_FILES[images][name]))
        {
            if(!empty($value))
            {
                $NewImageName = $t."_offer_".$value;
                copy($_FILES[images][tmp_name][$key], "re_images/".$NewImageName);
                $MyImages[] = $NewImageName;
                //Below is the convertion of images if servers uses IMAGEMAGICK
                exec("convert re_images/$NewImageName -resize 460x400 -quality 65 -compress JPEG re_images/$NewImageName");
            }
        }    

        if(!empty($MyImages))
        {
            $ImageStr = implode("|", $MyImages);
        }

    }


this example is also using imagemagick to compress the image
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 10:17PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month