
June 16th, 2004, 08:51 PM
|
|
Registered User
|
|
Join Date: Jun 2004
Posts: 28
Time spent in forums: 10 h 10 m 46 sec
Reputation Power: 0
|
|
|
PHP Image upload script
Hello, I was wondering if someone could make/help me make a few mods to my image upload script, here is what I have right now:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Image Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="http://levade.homeip.net/fszone/forums/cache/css_1.css" rel="stylesheet" type="text/css">
<!-- waiting for php corrections
<script language='Javascript'>
function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}
function doact(a, d)
{
if (a == 's')
{
var dod = eval("document.result."+d);
dod.focus();
dod.select();
}
else if (a == 'c')
{
var doc = eval("document.result."+d);
cp = doc.createTextRange();
doc.focus();
doc.select();
cp.execCommand("Copy");
}
else if (a == 'v')
{
var dob = eval("document.result."+d);
var c = dob.value;
code = replace(c,'<','<');
code = replace(code,'>','>');
code = replace(code,'<br>','\n');
code = replace(code,'\n','<br>');
nwin = open('', 'Code', 'toolbar=no,location=no,scrollbars=yes,resizable=no,statusbar=no,top=0,width=500,height=500');
nwin.document.open();
nwin.document.write("<title>View Code</title><style type='text/css'><!--a:link {color: #000000;text-decoration: none;}a:visited {color: #000000;text-decoration: none;}a:hover {color: #000000;text-decoration: underline;}.table {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 9px;color: #000000;}input {font-family: Verdana;font-size: 9px;color: #000000;background-color: #A2AEC5;border: 1px solid #000000;}.textarea {font-family: Verdana;font-size: 9px;color: #000000;background-color: #A2AEC5;border: 1px solid #000000;}.hidden {VISIBILITY: hidden; POSITION: static}.show {VISIBILITY: visible; POSITION: static}
</style><body bgcolor='#7A8AAA'><center><div align='justify'><table width='90%' height='211' border='0' align='center' cellpadding='3' cellspacing='3' class='table' style='background-color: #8E9EBA; border: 1px solid black'><tr><td align='justify' valign='top'>");
nwin.document.write(code);
nwin.document.write("</td></tr></table><center><p><span style='font-family: Verdana; font-size: 9px; color: #000000;'><a href='javascript:location.reload()'>Reload</a> - <a href='javascript:self.close()'>Close Window</a></span></div>");
nwin.document.close();
}
}
</script>-->
</head>
<body>
<table width="100%" cellspacing="1" id="submenu" align="right">
<tr>
<td valign="top"> <img src="http://levade.homeip.net/fszone/forums/style_images/1/tile_back_small.gif" width="100%" height="22">
<font size="4" color="3A4F6C">
<div align="center">
Upload
<br>
</font>
<font size="1" color="3A4F6C">
<!--Upload form-->
<?php
error_reporting(0);
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";
//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
die ("upload_files directory doesn't exist");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name ==".jpg") {
$message = "Invalid File Name Specified, be sure its a '.jpg'";
return $message;
}
//File Size Check
else if ( $file_size > 256000) {
$message = "The file size is too big.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"[IMG]<a href=$file_url>$file_url</a>[/IMG]" :
"Somthing is wrong with uploading the image.";
return $message;
}
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
<br><br>
Upload Image
<br>
<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>
</font>
<br>
<font size="2" color="red">
Please Click Upload Only ONCE! May Take A While To Upload!
</font>
<br><br>
<font size="3" color="3A4F6C">
Please Note The Following Guidelines:
<br>
</font>
<font size="1.5" color="3A4F6C">
- Max picture size of 256 KB's
<br>
- Only accepts '.jpg'
<br>
-If you have problems please <a href="mailto:Martymydog@aol.com?subject=Image Uploader&">E-Mail us</a>. (Martymydog@aol.com)
</div>
</font>
<br><br>
</td>
</tr>
</table>
</body>
</html>
However, I want to do two different things. I want the script to change the URL to a random one, and I want the result message to display this:
Code:
-Click here to insert into post-
<br>
<input type=\"button\" value=\"Insert Into The Post\" onClick=\" opener.document.REPLIER.Post.value += '\\n[IMG]<!--URL to image-->[/IMG]\\n'; \">" :
<br>
-OR-
<form name="result">
<textarea name="result" cols="68" rows="1" wrap="" class='textarea' type="hidden">
[IMG]<!--URL to image-->[/IMG]
</textarea>
<br>
<input onclick="doact('s', 'result')" type="button" value="Select All">
<input onclick="doact('c', 'result')" type="button" value="Copy">
</form>
can anyone show me how to do this, or do it for me
Thanks,
Eric.
|