I have a php page where people can upload pictures into a directory on my web site.
I would like a script that tells that php uploader to not only upload files but to add a line of code into another file. Is this do-able?
Here’s the code for the php uploading file:
[code=php]<?php
@session_start();
$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 = “template/images/random/”;
$upload_url = $url_dir.”/template/images/random/”;
$message =””;
/************************************************************
* Create Upload Directory
************************************************************/
if (!is_dir(“template/images/random”)) {
if (!mkdir($upload_dir))
die (“upload_files directory doesn’t exist and creation failed”);
if (!chmod($upload_dir,0755))
die (“change permission to 755 failed.”);
}
/************************************************************
* Process User’s Request
************************************************************/
if ($_FILES[‘userfile’]) {
$message = do_upload($upload_dir, $upload_url);
print “<script>window.location.href=’$url_this?message=$message'</script>”;
}
else if (!$_FILES[‘userfile’]);
else
$message = “Invalid File Specified.”;
/************************************************************
* List Files
************************************************************/
$handle=opendir($upload_dir);
$filelist = “”;
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= “<br><a href=’$upload_dir$file’>”.$file.”</a>”;
}
}
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 ==””) {
$message = “Invalid File Name Specified”;
return $message;
}
//File Size Check
else if ( $file_size > 6144) {
print $file_size;
$message = “The file size is over 6KB.”;
return $message;
}
//File Type Check
else if ( $file_type == “text/plain”
|| $file_type == “application/force-download”
|| $file_type == “application/octet-stream”
|| $file_type == “image/bmp”) {
$message = “Sorry, you cannot upload that type of file.” ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0755))
$message = “Sorry, the change permission to 755 failed.”;
else
$message = ($result)?”$file_name($file_type) uploaded successfully.” :
“Somthing is wrong with uploading a file.”;
return $message;
}
?><title>Upload a "Random Image"</title><body bgcolor=”#000000″ text=”#FF0000″ link=”#FFFF00″>
<center>
<p><font color=red>
<?=$_REQUEST[message]?>
</font></p>
<p><strong><font color=”red” size=”7″>Random Upload </font></strong> </p>
<p>Upload a file so that it may be used as a "Random Image".</p>
<p>100×100 pixels max size and filesize max is 6KB. <br>
</p>
<form name=”upload” id=”upload” ENCTYPE=”multipart/form-data” method=”post”>
Upload File <input type=”file” id=”userfile” name=”userfile”>
<input type=”submit” name=”upload” value=”Upload”>
</form>
<br>
<br>
<b>Files Already Uploaded </b>
<hr width=70%>
<?=$filelist?>
</center>
<?
if ($_REQUEST[debug]==1) print “——————Debugging Info—————-<br>”;
if ($_REQUEST[debug]==1) print “site=$site_name<br>dir=$url_dir<br>url=$url_this<br>”;
if ($_REQUEST[debug]==1) print “upload dir=$upload_dir<br>upload url=$upload_url<br>”;
?>