Solved

Uploading files

Posted on 2001-06-05
8
263 Views
Last Modified: 2006-11-17
Hello, Experts.

How i can upload image from browser to server, trought PHP?
I will be very glad for your answers. I am using php 4.x.

Thank you.

--
sandis
0
Comment
Question by:sviksna
[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
8 Comments
 
LVL 8

Expert Comment

by:us111
ID: 6156118
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6158534
0
 
LVL 1

Author Comment

by:sviksna
ID: 6159576
eeeh, isn't there any simply code for uploading a file?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Expert Comment

by:rick2001
ID: 6159615
How about this for uploading a file into d:\data on a win32 system?


<html>
<head>
<title>Upload a File</title>
</head>
<body>
<h1>Upload a File</h1>
<form enctype="multipart/form-data" method="post" action="do_upload.php">
<p><strong>File to Upload:</strong><br>
<input type="file" name="img1" size="30"></p>
<P><input type="submit" name="submit" value="Upload File"></p>
</form>
</body>
</html>

<?
if (is_uploaded_file($img1))
{
        copy($img1, "d:\\data\\".basename($img1_name))
        or die("Couldn't copy the file!");
        print "File uploaded.";
}
else
{
        die("No input file specified");
}
?>
0
 
LVL 8

Expert Comment

by:us111
ID: 6159636
0
 

Expert Comment

by:jbkerra
ID: 6166153
<?
if(isset($submit)){

if ($upme_name != "") {

if(!(copy("$upme", "/your/dir/for/uploads/$upme_name")))
  print(error."bad");      
         
} else {

    die("No input file!");

}
print("Thanks for the $upme_name file!");    
}

?>
<HTML>
<HEAD>
<TITLE>Uploads</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION='<? print("$PHP_SELF?"); ?>' ENCTYPE="multipart/form-data" > 
File <INPUT TYPE="file" NAME="upme" SIZE="30"><br>
<INPUT TYPE="submit" NAME="submit" VALUE="Send">
</FORM>

</BODY>
</HTML>
0
 
LVL 1

Accepted Solution

by:
anupkarade earned 20 total points
ID: 6230231
Just Copy paste this code make the relevant changes as instructed in the commented portion and you have
the answer here


<--! The First Page where the image is browsed for uploading--->

<HTML>
<HEAD>
<TITLE>Upload example</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION="resultUpload.php" ENCTYPE="multipart/form-data">

<p><strong>File</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Send"></p>

</FORM>

</BODY>
</HTML>




/*resultupload.php*/
<? php

$ImgArr=array("image/pjpeg","image/gif","image/png");
$i=0;

if ($img1_name!="") {

   if($img1_size > 2000000) {
       echo "File size is bigger than 20kb!";
             exit;
     }

     while($i<3){
/* Change the relative path where you want to load images but the folder should be within the virtual
folder and put ./Yourfolder if it is in the same direcory where your page is currently located or ../yourfolder
if it is outside the folder   */
      if($ImgArr[$i]==$img1_type){
         copy("$img1","./Images/$img1_name")
       or die("No copy!");
       echo "File name : $img1_name <BR>";
       echo "File size :$img1_size <br>";
       echo "File Type :$img1_type <br>";
       exit;
 
      }

      $i++;
     }

   echo "Not A Image file!!!";
}

else
{

  die("No input file!");

}

?>



                       Anup
0
 
LVL 1

Author Comment

by:sviksna
ID: 6230468
This sample worked without any bugs. 10x a lot :)

Sandis.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 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