hi i am working on an upload script, this is what i have so far
$file_dir = “/home/richardt/public_html/”;
foreach( $HTTP_POST_FILES as $file_name => $file_array ) {
print “path: “.$file_array[‘tmp_name’].”<br>n”;
print “name: “.$file_array[‘name’].”<br>n”;
print “type: “.$file_array[‘type’].”<br>n”;
print “size: “.$file_array[‘size’].”<br>n”;
$file_name = $file_array[‘name’];
if( is_uploaded_file( $file_array[‘tmp_name’] ) ) {
move_uploaded_file( $file_array[‘tmp_name’], “$file_dir/$file_name”) or die (“Couldn’t Copy”);
}
}
now this will upload the file into the directory specified with the filename of what it was on the users computer
however a title was entered on the same page as they selected the file (on the form), and i would like the file name to just be
$HTTP_POST_VARS[“new”] . extension of what it is (jpg only upload)
eg
Title = Foo
Picture = xplogo.jpg
Click Add, it uploads
xplogo.jpg is on my server but called foo.jpg
also if its not too much to ask i only want to be able to upload a jpg, i can do it js but would prefer to use php, i think i can code this bit, so ill give it a try and post back if i get it, many thanks
Rich
//Edit ive managed to limit upload types
if(preg_match(“/.jp/i”, $file_array[‘name’])){
$file_name = $file_array[‘name’];
if( is_uploaded_file( $file_array[‘tmp_name’] ) ) {
move_uploaded_file( $file_array[‘tmp_name’], “$file_dir/$file_name”) or die (“Couldn’t Copy”);
}
} else {
echo “Invalid file type, please <a href=javascript:history.go(-1);>go back</a> and upload a .jpg file”;
exit();
}
}