Speedsoft Home Page
 
Order Hosting Services Services and Pricing Support Home Page Search Speedsoft Contact Information Site Map
: PHP Upload
See Also
MySQL
PHPInfo
Consulting


Some times you might need to allow people to upload data files or image files to your web site through a web page. Here is a very basic page which would do this.  Save this to a file with a ".php" filename extension and change YOURDIRECTORY to whatever your directory name is on the server (usually the same as your username).
 

<html>
<head>
<title>Picture Upload Page</title>
<%
if (isset($submit)) {
   if ($pic_size > 0) {

        // let's get rid of yucky characters in the filename
        $fnamefrom = ' ()/\%"'."'^&*@!`~";
        $fnameto = "+__________+___";
        $fname = strtr($pic_name,$fnamefrom,$fnameto);

        exec("/usr/bin/cp $pic /usr/local/etc/httpd/vhosts/YOURDIRECTORY/mypics/$fname");         $goodsave = 1;
   }
}
%>
</head>
<body>
<%
if ($goodsave == 1) {
     %>
    <p>The picture, $pic, was successfully saved to the server.</p>
    <%
}
%>

<form action="<%echo $PHP_SELF%>" method="post" enctype="multipart/form-data">
<input type="file" name="pic" size="25">
<input type="submit" name="submit">
</form>

</body>
</html> 
Home | Order | Services | Support | CGI Central | E-Commerce | Search | Contact Us | Site Map | Links
Copyright © 1995-2008 Speedsoft, LLC. All rights reserved.