/    Sign up×
Community /Pin to ProfileBookmark

I’m looking for a script

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 &quot;Random Image&quot;</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 &quot;Random Image&quot;.</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>”;
?>

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsMar 06.2005 — Easy as pie.
[code=php]
$file = fopen("PATH TO FILE",'a+')
fwrite($file,$_FILES['userfile']['name']."n");
fclose($file);
[/code]
Copy linkTweet thisAlerts:
@ErikLindemannauthorMar 06.2005 — thank you!

Where should I put it though?

I know next to nothing about scripting...

and what does 'a+' mean?

You see, I have a script that I'm using that randomizes images and that script looks like this:

[CODE]
<SCRIPT LANGUAGE="Javascript"><!--
function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = "<img src='template/images/random/1.gif' border='0'>"
image[number++] = "<img src='template/images/random/2.gif' border='0'>"
image[number++] = "<img src='template/images/random/3.gif' border='0'>"
image[number++] = "<img src='template/images/random/4.jpg' border='0'>"
image[number++] = "<img src='template/images/random/5.gif' border='0'>"
// keep adding items here...

increment = Math.floor(Math.random() * number);

document.write(image[increment]);

//--> </SCRIPT>
[/CODE]


and I want the php script to add
[CODE]
image[number++] = "<img src='template/images/random/[image file]' border='0'>"
[/CODE]

right inside that little area right there...
×

Success!

Help @ErikLindemann spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...