My Upload Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
epheterson
Forum Newbie
Posts: 2
Joined: Mon Nov 24, 2003 9:22 pm

My Upload Script

Post by epheterson »

Hey, I have an upload script that currently
-uploads to any desired folder
-prohibits index and php files
-Doesn't allow overwriting of files
-Displays error-specific message when error
-Displays success message when success

What I would like for my script to do is display a link to the file that was just uploaded. My idea is i just put the path to my upload folder in text, and reprint the filename at the end. Anybody know how to do that?

Heres the script:

Code: Select all

<html>
<head>
<title>pheterson.com - upload script</title>
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http://www.pheterson.com/upload/"> 
</head>
<? 
/*upload.php*/ 


if ($img1_name != "") &#123; 

if(!(file_exists("/home/pheterso/www/upload/$img1_name")))&#123; 

if(!(eregi("index.htm|index.html|php",$img1_name)))&#123; 

@copy("$img1", "/home/pheterso/www/upload/$img1_name") 
or die("<b>No Copy!</b><br>There was a problem copying your file. Most likely the server timed out. Try again or give up."); 

&#125;else&#123;print "<b>No Copy!</b><br><br>Uploading of index and php files is prohibited.<br>(index.html, index.htm, and any file with a .php extension.)";exit;&#125; 

&#125;else&#123;print "<b>No Copy!</b><br>File Already Exists. Please rename your file and try again.";exit;&#125; 


&#125;else &#123; 

die("<b>No input file!</b><br>You did not select a file to upload."); 

&#125; 




?> 

<b>Your file has been uploaded successfully. Please wait to continue.<br><br>

Or... If you're a lazy ass, <a href="http://www.pheterson.com/upload/">click here</a>.
</html>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

<b>Your file has been uploaded successfully. Here is the link: <a href="http://www.pheterson.com/upload/<?php echo $img1_name; ?>">http://www.pheterson.com/upload/<?php echo $img1_name; ?></a><br><br>
epheterson
Forum Newbie
Posts: 2
Joined: Mon Nov 24, 2003 9:22 pm

Post by epheterson »

Awesome, that worked perfectly!
Post Reply