grahamb314 Posted October 22, 2008 Share Posted October 22, 2008 Hi all, I have this messy code below: It's been a while since I last looked at it and I need some help to: A) Limit upload size to 5mb B) replace this symbol: ' with nothing because the directory that is being uploaded to is created in this code and the dir can not have a ' in it since php puts a \ infront of it so the directory name messes up! (The session at the top is the upload directory) - I can also not remember which variable is the actual file to upload! - Otherwise I might be able to do this myself! Hope you understand! Thanks, Code: <?php $filename = "../../../../shares/shows/{$_SESSION['directory']}"; //$filename = "/uploads/{$_SESSION['directory']}"; if (is_dir($filename)) { echo "The folder: $filename exists"; echo "<br>"; $allowed_types = array('mp3', 'mp2', 'mp1', 'wav', 'ogg'); //mp3, mp2, mp1, wav and ogga foreach($_FILES as $file_name => $file_array) { if (is_uploaded_file($file_array["tmp_name"])) { $image_extension = strtolower(str_replace(' ', '', $file_array["name"])); $image_extension = explode('.', $image_extension); $image_extension = strtolower($image_extension[count($image_extension) - 1]); if (in_array($image_extension, $allowed_types)) { move_uploaded_file($file_array["tmp_name"], $filename.'/'.$file_array["name"]) or die ("Couldn't copy"); echo "The File: ".$file_array["name"]."<br/>\n"; echo "Was uploaded"; echo "TEST"; } else { echo "Filetype not allowed. You can only upload mp3, mp2, mp1, wav and ogg files "; } } } } else { mkdir("{$filename}", 0700); echo "The folder did not exist but has now been created"; echo "<br>"; $allowed_types = array('mp3', 'mp2', 'mp1', 'wav', 'ogg'); //mp3, mp2, mp1, wav and ogg foreach($_FILES as $file_name => $file_array) { if (is_uploaded_file($file_array["tmp_name"])) { $image_extension = strtolower(str_replace(' ', '', $file_array["name"])); $image_extension = explode('.', $image_extension); $image_extension = strtolower($image_extension[count($image_extension) - 1]); if (in_array($image_extension, $allowed_types)) { move_uploaded_file($file_array["tmp_name"], $filename.'/'.$file_array["name"]) or die ("Couldn't copy"); echo "The File: ".$file_array["name"]."<br/>\n"; echo "Was uploaded"; //echo $filename; } else { echo "Filetype not allowed. You can only upload mp3, mp2, mp1, wav and ogg files "; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/129586-solved-php-upload-error-checking/ Share on other sites More sharing options...
grahamb314 Posted October 22, 2008 Author Share Posted October 22, 2008 I saw somewhere that there is a strip characters method - Could this be used, if so how? Link to comment https://forums.phpfreaks.com/topic/129586-solved-php-upload-error-checking/#findComment-671811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.