Creating FTP upload page

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Mon Mar 17, 2003 6:44 am

Why don't you just use a regular copy process ? :?

$source_file (Its the the uploading input)

Code: Select all

<?
$path="path to directory";
$max_size=1000000;
$source_file_size_kb=(int)($source_file_size/1000);
if(is_uploaded_file($source_file)){
if($source_file_size>$max_size){
print "<font color=red><b>ERROR</b>:</font> The File's Size Is More Then <b>1Mb</b>!<br>"; exit;}
if($source_file_type=="text/html" || $source_file_type=="application/octet-stream"){
print "<font color=red><b>ERROR</b>:</font> You Are <b>Not</b> Allowed To Upload This Type Of File!<br><br>"; exit;}
$do=copy($source_file, $path . $source_file_name);
if($do){
print "<font color=red><b>Name</b>:</font> $source_file_name<br>";
print "<font color=red><b>URL</b>:</font> $http://.../$source_file_name<br>";
print "<font color=red><b>Size</b>:</font> $source_file_size_kb KB <br>";
print "<font color=red><b>Type</b>:</font> $source_file_type<br><br>";
if($source_file_type=="image/gif" || $source_file_type=="image/jpg" || $source_file_type=="image/jpeg" || $source_file_type=="image/bmp"){
print "<u><b>Picture Preview</b></u><br><br>";
print "<img border=0 src=http://.../$source_file_name><br><br><br>";
}
}
elseif(!$do){
print "<font color=red><b>ERROR</b>:</font> Uploading Failed! Please Try Again Or Email The <b>Webmaster</b>.<br><br>";
}
}
?>

sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Tue Mar 18, 2003 1:25 am

Explanation:
:arrow: You can set max size for the uploaded files - 100000 = 1MB.
:arrow: If the file that you want to upload is bigger then 1MB it will show an error.
:arrow: You can set type of files that are not allowed to be uploaded - html,asp...
:arrow: You tell the code what to do after the file is uploaded - here it shows it's name... url... size and type and if its an image file, then it will preview the image to the user...

Very Easy To Understand :P

:idea: You need to set a form...

<form method="POST" action="">
<input type="file" name="source_file" value="<?=$source_file?>">
<br>
<input type="submit" name="upload" value="Upload">
</form>
Last edited by sleepingdanny on Wed Mar 19, 2003 3:29 am, edited 3 times in total.

sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Wed Mar 19, 2003 3:30 am

I made a small mistake in the form code... its fixed now! :P

ph
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Mar 13, 2003 2:14 am

Wed Mar 19, 2003 3:34 am

For $59 you can buy the dreamweaver extension 'pure php upload'. It does exactly what you want (I think), but you need to use Dreamweaver (MX). See this site: http://www.dmxzone.com/ShowDetail.asp?NewsId=4509.

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

Wed Mar 19, 2003 8:48 am

Or you could use the freely posted code above.

ph
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Mar 13, 2003 2:14 am

Wed Mar 19, 2003 9:40 am

That indeed is the $59 saving option :)

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

Wed Mar 19, 2003 9:59 am

Lol... I have Dreamweaver MX, what is it exactly you were talking about anyway?
Terra Design, my business and sole / huge PHP project... a fully dynamic and adaptive site engine.

ph
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Mar 13, 2003 2:14 am

Wed Mar 19, 2003 10:03 am

It's an extension, meaning that you can download and install it with ease, and then it will integrate in Dreamweaver as if it was pre-installed. I've been looking for an option to do php uploading, and found this extension. I haven't bought it (yet), but it seems to be a very easy and usefull one. You can find more information at the website I gave.

sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Thu Mar 20, 2003 2:59 am

Are you talking about the code that I'v writed :?:
By the way the form and the code has to be in the same page...
Do this :arrow:

<form>
.....
</form>
<?
....
?>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests