AJ_V Posted March 11, 2007 Share Posted March 11, 2007 Hi everyone, ran into a slight problem when trying to modify my single file upload that includes renaming the file uploaded to include a random four digit number at the begining. This is my code for the single file upload: <?php session_start(); $target = basename($_FILES['uploaded']['name']) ; $ok = 100; $target = str_replace('php', 'unsupported', $target); $random_digit = rand(0000,9999); $target = $random_digit.$target; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { if ($uploaded_size > 5500000) { echo "Your file is too large, please ZIP or RAR to try again!<br>"; $ok = 0; } else { $_SESSION['filename'] = 'http://vee-media.com/uploaded/' . $target; $ok = 100; } } else { $ok = 0; } if($ok !== 100){ header('Location: http://www.vee-media.com/not_uploaded.php'); }else{ header('Location: http://www.vee-media.com/uploaded.php'); } ?> That code works like a dream, I attempted to change it to this: <?php session_start(); $target = basename($_FILES['uploaded']['name']) ; $target = basename($_FILES['uploaded2']['name']) ; $target = basename($_FILES['uploaded3']['name']) ; $ok = 100; $target = str_replace('php', 'unsupported', $target); $random_digit = rand(0000,9999); $random_digit2 = rand(0000,9999); $random_digit3 = rand(0000,9999); $target = $random_digit.$target; $target2 = $random_digit2.$target2; $target3 = $random_digit3.$target3; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) if(move_uploaded_file($_FILES['uploaded2']['tmp_name2'], $target2)) if(move_uploaded_file($_FILES['uploaded3']['tmp_name3'], $target3)) { if ($uploaded_size > 5500000) { echo "Your file is too large, please ZIP or RAR to try again!<br>"; $ok = 0; } else { $_SESSION['filename'] = 'http://vee-media.com/uploaded/' . $target; $ok = 100; } } else { $ok = 0; } if($ok !== 100){ header('Location: http://www.vee-media.com/not_uploaded.php'); }else{ header('Location: http://www.vee-media.com/uploaded.php'); } ?> And subsequently comes up with this error message: Warning: move_uploaded_file(4861sammy.jpg): failed to open stream: Permission denied in /hsphere/local/home/cvenning/vee-media.com/multi.php on line 14 Warning: move_uploaded_file(): Unable to move '/tmp/phpkgwCCQ' to '4861sammy.jpg' in /hsphere/local/home/cvenning/vee-media.com/multi.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/cvenning/vee-media.com/multi.php:14) in /hsphere/local/home/cvenning/vee-media.com/multi.php on line 37 If anyone has any idea at all what is going wrong, I would be very grateful if you could help me!! Regards, AJ. Link to comment https://forums.phpfreaks.com/topic/42173-problems-with-multi-file-upload-and-random-four-digit-number-filename/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.