Hi,

I was wondering if there's a tutorial on making a website that offers free hosting. I know how to upload files with PHP, so I posted this topic here.

Thanx.

2 options: 1. Build your own web server, 2. Sign up for reseller hosting package

Unless you build the free hosting service for marketing purposes (generate many users who looking for free stuffs), offering free hosting service need serious money input!

Hi Zippee,

Thanks. The site will only host a few of my friend's site - no one else. I wanted to make it so when they sign up a directory is created that's password protected with their password. Is there a way to do this? If there is, could you tell me or show me a tutorial?

Thanks a lot!

The site will only host a few of my friend's site - no one else. I wanted to make it so when they sign up a directory is created that's password protected with their password. Is there a way to do this? If there is, could you tell me or show me a tutorial?

It will be very similar to my store2go.net site.
Create a php file that allow your friends to enter directory name, user name and password. Use mkdir function to create folder and (use fopen and fwrite) create .htpasswd file in the folder with their username and password. I never use .htpasswd so cannot comment.

Hi,

Thanks! Can you explain more about the file writing and the make directory function? Thanks!

Also, if anybody knows about .htpsswrd, I would appreciate your help.

Thanks again.

Hi Zippee,

Also, instead of uploading through the browser, can they upload through an FTP? I'll be hosting through Apache Webserver on my own computer. The web address will be my email address.

Thanks!

sorry - i meant the website address will be my IP address

Hi Everyone,

I got the file creation to work! Is there a way to make a page where the user enters a username and password and it takes you to an upload page where you can upload files? I already know how to make the upload page. The only problem is that I can't use databases - they don't work on my computer!

Thanks for your help in advanced!

1. You can create a simple login page (with or without database connection). If without db, then use txt file to save data (but is limited to small number of users only). After successfully login, redirect user to upload page.
2. Unless you want to upload file to database, you can uploading file directly into folder without a database running on your machine.
3. You propably need to install mysql on your server to run database. Also install phpMyAdmin for better user interface.

P/S: not good enough to comment on FTP side. sorry!

Create folder on the fly:

// get folder name - user define
$folder_name = $_GET['fname'];
// where the folder need to be created
$path = 'user/';
// check if folder already exists, if not create new folder
if (!is_dir($folder_name)) {
  mkdir($path.$folder_name, 0777) or die ('Could not create folder'); 
}

Do check php.net for permission mode. 0777 is open to public to read, write and execute.

Hi Zippee,

First, thanks for all your help. Second, I was wrong about knowing how to upload files! Do you know how? I already made a form with a file field.

Thanks again.

Hi Zippee!

Thanks! I get some errors so I attached the code:
login.php:

<!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>CinnaHost Login</title>
</head>

<body bgcolor="#3366FF">
<img src="logo.png" width="939" height="61" />
<br />
<table width="940" height="215" border="1">
  <tr>
    <td width="103" height="209"><center>
      <h3>CinnaHost<br />
        <br />
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
        <param name="BGCOLOR" value="#3366FF" />
        <param name="movie" value="button1.swf" />
        <param name="quality" value="high" />
        <embed src="button1.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
        </object>
        <br />
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
          <param name="BGCOLOR" value="#3366FF" />
          <param name="movie" value="button4.swf" />
          <param name="quality" value="high" />
          <embed src="button4.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
        </object>
        <br />
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
          <param name="BGCOLOR" value="#3366FF" />
          <param name="movie" value="button2.swf" />
          <param name="quality" value="high" />
          <embed src="button2.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
        </object>
        <br />
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
          <param name="BGCOLOR" value="#3366FF" />
          <param name="movie" value="button3.swf" />
          <param name="quality" value="high" />
          <embed src="button3.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
        </object>
        <br />
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
          <param name="BGCOLOR" value="#3366FF" />
          <param name="movie" value="button5.swf" />
          <param name="quality" value="high" />
          <embed src="button5.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
        </object>
      </h3>
    </center></td>
    <td width="821" bgcolor="#0000FF"><center>
      <h2>CinnaHost Login/Upload:</h2>
    </center>
    <form action="in.php" method="post" enctype="multipart/form-data">
	  <p><strong>          <font color="#FFFFFF">Site Name:</font><br />
	  <input name="site" type="text" />
	  <br />
	  <br />
	  <font color="#FFFFFF">Password:</font><br />
	  <input type="password" name="password" />
	  </strong><strong></strong>
	  <strong>	  <br />
	  <br />
	  <font color="#FFFFFF">File To Upload:</font>
	  <br />
      <input type="file" name="updelfile" />	  
      <br />
	  <br />

	  <input type="submit" value="Login" />
</strong></p>
    </form></td>
  </tr>
</table>
</body>
</html>

in.php:

<html>
<head>
<title>CinnaHost Login</title>
</head>
<body bgcolor="#3366FF">
<center><h1><font color="#FFFFFF">Uploading...</font></h1>
<h2><font color="#FFFFFF">To Upload More Files, Click <a href="login.php"><font color="#FFFFFF">Here</font></a>.</font></h2>
</h1></center>


<?php
$filename = "../public/$_POST[site]/pswrd.pswrd";
$fp = fopen($filename,"r")  or die ("Login Not Working - please try again.");
$pswrd = fgets($fp);
$attempt = "$_POST[password]";
if($pswrd == $attempt) {
	echo "Login Successful!";


	//START UPLOAD
	
	$file = $_FILES["$_POST[updelfile]"];
	// set the file type you will allow to avoid abuse to your server
	$accept = array('pdf','doc','xls','ppt','txt','zip','jar','html','html','php','rtf','jpg','png','gif','txt','java','cpp');
	if($file["size"] > 0) {
	$file_name = basename($file["name"]);
	$ext = substr($file_name, -3, 3);
	}
	// validate file
	if ($file["size"] > 5000000) {
	  echo "Filesize over 5 mb limit.<br>\n";
	}
	elseif(!in_array($ext, $accept))  {
	  echo "Invalid file format. <br>\n";
	}
	else {
	  // set folder path to which image uploaded
	  $uploaddir = "../public/$_POST[site]";
	  //copy the file to some permanent location
	  if (move_uploaded_file($file['tmp_name'], $uploaddir.$file['name'])) {
		echo "File has been uploaded.<br>\n";
	  }
	  
	  //END UPLOAD
	  
	  
		else {
		echo "Error found. Please try again. <br>\n";
		}
    } 
}
else {
	echo "Login Failed - please try agin.";
}
?>

</body>
</html>

Thanks!

What errors you get?

You may want to use echo or print at each stage to find out where the errors were. I would suspect your $filename may be an error and always use $_POST.

actually, $filename works. Here's the errors:

Notice: Undefined index: updelfile in c:\phpdev5\www\public\in.php on line 22

Notice: Undefined index: in c:\phpdev5\www\public\in.php on line 22

Notice: Undefined variable: ext in c:\phpdev5\www\public\in.php on line 33
Invalid file format.

If you want to view the page, go to http://192.168.1.42/public/login.php You can use "cinnatech" for a site name and "pwrd" for the password. If you try to upload a file and click login, you'll see the error messages.

I can't access the site as 192 is your localhost address, not the true IP address.
I have no idea about the first two. The thrid may be because you upload files that wasn't define in the script (in my other post http://www.daniweb.com/techtalkforums/thread31803.html there is something called $accept that prevent undefined file being upload).

Hey zipee can you help me how to create a free webhost i need my site to create game its called Star Wars Jedi Academy.My friend from that game tell im just must go to game an create game but there is no ip adress or how to call my server so can you please help me...i wait your answer.....
Tnxy

You Can Try joining http://www.myownfreehost.net
im a Member and i Can Host Unlimited Sites,
its Free {but theres also Paid Host if ya Wanna pay a Bit}


P.S There is Plenty of Features and you can have no Banners or Adds {or Add Some if you want}

We are talking about how to create a free webhost service , not looking for a free webhost, thanks anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.