/    Sign up×
Community /Pin to ProfileBookmark

when file is finished upploadin then execute next command

I have commente in the code what I want to do.

But basicly what I want to do is: When a file has finished upploading* I want to run another command (witch works if i run it in a clean php file) But for some reason it will not work when I paste the code into the uppload script.

Why is that?

*uploading works somewhat some .wmv files work some don´t.

[CODE]<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 9999999999999990000000000;

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array(‘.wmv’,’.jpg’,’.png’,’.gif’);

//Allow file delete? no, if only allow upload only
$DELETABLE = no;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/************************************************************
* Setup variables
************************************************************/
$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 = “files/”;
$upload_url = $url_dir.”/files/”;
$message =””;

/************************************************************
* Create Upload Directory
************************************************************/
if (!is_dir(“files”)) {
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 ($_REQUEST[del] && $DELETABLE) {
$resource = fopen(“log.txt”,”a”);
fwrite($resource,date(“Ymd h:i:s”).”DELETE – $_SERVER[REMOTE_ADDR]”.”$_REQUEST[del]n”);
fclose($resource);

if (strpos($_REQUEST[del],”/.”)>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print “<script>window.location.href=’$url_this?message=deleted successfully'</script>”;
}
}
else if ($_FILES[‘userfile’]) {
$resource = fopen(“log.txt”,”a”);
fwrite($resource,date(“Ymd h:i:s”).”UPLOAD – $_SERVER[REMOTE_ADDR]”
.$_FILES[‘userfile’][‘name’].” ”
.$_FILES[‘userfile’][‘type’].”n”);
fclose($resource);

$file_type = $_FILES[‘userfile’][‘type’];
$file_name = $_FILES[‘userfile’][‘name’];
$file_ext = strtolower(substr($file_name,strrpos($file_name,”.”)));

//File Size Check
if ( $_FILES[‘userfile’][‘size’] > $MAX_SIZE)
$message = “The file size is over 2MB.”;
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = “Sorry, $file_name($file_type) is not allowed to be uploaded.”;
else
$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 .= “<a href=’$upload_dir$file’>”.$file.”</a> – URL: <b>$upload_url$file</b>”;
if ($DELETABLE)

$filelist .= ” Added at “.date(“d-m H:i”, filemtime($upload_dir.$file))
.””;
$filelist .= ” <a style=’text-decoration:none; font-weight:bold’ href=’?del=$upload_dir”.urlencode($file).”‘ title=’delete’>x</a>”;
$filelist .=”<br>”;
}
}

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES[‘userfile’][‘tmp_name’];
$file_name = $_FILES[‘userfile’][‘name’];
$file_name = str_replace(“\”,””,$file_name);
$file_name = str_replace(“‘”,””,$file_name);
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name ==””) {
$message = “Invalid File Name Specified”;
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = “change permission to 777 failed.”;
else
$message = ($result)?”$file_name was uploaded successfully.” :
“Something is wrong with uploading the file.”;
return $message;

//// PROBLEM HERE!!!!!!!!!
////
////
//// Now I want to wait untill the file has beenv writen then execute below ////commans
////
////
////hopfully $file_name is still in memory so I can use this later
////
////Big problem, for some reason it will not execute the shel_exec command ///when have it in this file. works grate in a separate file
//// where I hard code what it shall do, but even hard coding will not work in ///this file

// $my_string = ‘my.wmv’; for test
shell_exec(“C:\Inetpubwwwrootup2filescmd.exe /c C:Inetpubwwwrootup2filesflashvideomx (my.wmv) myflash”);

}
?>

<html>
<head>
<title>Simple uploader</title>
<link rel=stylesheet href=style.css>
</head>
<body>
<br><br>
<center>
<font color=red><?=$_REQUEST[message]?></font>
<br>
<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><b><u>Uploaded files:</b></u><br><br>

<?=$filelist?><br>Developed By
<a style=”text-decoration:none” href=”http://savasplace.com”>Sava’s Place.com</a>
</sup></small>
</center>

[/CODE]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 08.2007 — Example from the PHP documentation:[code=php]shell_exec("C:\path\to\cmd.exe /c C:\batchfile.cmd");[/code]See: http://us2.php.net/manual/en/function.shell-exec.php for more...
Copy linkTweet thisAlerts:
@fredrikauthorJan 08.2007 — ok. I have been thinking of that. But then I need to make a little script that writes the $file_name into the .cmd file. But it should be fairly easy when I find out how to write some text to a file.

So what i need to do is to write the following to an .cmd file and then have the script execute it

C:Inetpubwwwrootup2filescmd.exe /c C:Inetpubwwwrootup2filesflashvideomx (c:path$file_name) c:path$file_name*

Will search for som guides, but i would appreciate if someone give me some hinters to what comamnd´s is used to write text to a file if I dont find it myself.


*might want to figure out how to get the second $file_name minus the extension, but not important now will work
Copy linkTweet thisAlerts:
@fredrikauthorJan 08.2007 — weeeee it works perectly!

thanks for the help.

now to figure put why the uppload script is so ocky on with files of the same file format it want upload.
×

Success!

Help @fredrik 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,
)...