I dunno if this will help you or not. It is a script I was working on to simplify uploading to my own web directory. As it happens, it won't work for me because I don't want to leave write permissions set on my directory and CHMOD is not available to me on the server I wanted to use it. I am now looking at writing an FTP solution.
It is possible I am using the CHMOD functions improperly, if so I hope somebody pipes up 🙂 I also used the deprecated $HTTP_POST_VARS which can be replaced with $_POST
It does work if you have write permission on the directory, or if PHP is not in safe mode you can remove the comments from CHMOD and it should work. Here is the functional part of the code, it accepts the file from the form input named 'file1' and also the relative virtual path from an input named, oddly enough, 'path'. I am attaching the entire self posting script (if I do it right) if you want to throw it on your server and test the functionality.
//first collect the values being posted
$path=$HTTP_POST_VARS['path'];
$path.="/";
$file1=$HTTP_POST_FILES['file1'];
$file1_temp_name=$HTTP_POST_FILES['file1']['tmp_name'];
$file1_name=$HTTP_POST_FILES['file1']['name'];
$file1_type=$HTTP_POST_FILES['file1']['type'];
$file1_error=$HTTP_POST_FILES['file1']['error'];
// VERIFY AND UPLOAD NEW file
if (is_uploaded_file($file1_temp_name)) {
//transfer the file home
//CHMOD ($path, 0777);//(untested)unavailable in safe mode
echo $path.$file1_name."<br>";
copy($file1_temp_name,$path.$file1_name)
or $errmsg.="Transfer failed (copy)<br>";
//CHMOD ($path, 0755);//(untested)unavailable in safe mode
// verify upload
if (file_exists($path.$file1_name)) {
$errmsg.= $file1_name.
" was uploaded successfully<br>";
}else {
$errmsg.= $path.$file1_name." failed to upload<br>".
"Reported error: ".$file1_error."<br>";
}
echo "<br>";
echo "$errmsg";
}
EDIT: I dunno why the forum is breaking up the temp name variable like that. It's all prim and proper in 'edit' mode ??
EDIT AGAIN: It just dawned on me, CHMOD probably will NOT work as written. I added the "/" slash to $path which probably break it. To get CHMOD to work around that would mean declaring another variable, or removing the code that adds the "/" to $path then explicitly appending each instance of $path in th script. I ain't gonna play with it tonight, I have no way of verifying it anyway.