i am trying to create a hash directory for image files when they are uploaded by my users. my path is valid if i remove the '/' in the $filename string; however, that is my whole point. When a new file is uploaded I want it to go to: mysite.com/upload/post_id/sha1(post_id)/sha1(post_id)...
my current code produces this error:
Warning: move_uploaded_file(/home/me/domains/mysite.com/public_html/upload/0/da39a3ee5e6b4b0d3255bfef95601890afd80709/a3/5e) [function.move-uploaded-file]: failed to open stream: No such file or directory in /vz/home/me/domains/mysite.com/public_html/TEST.php on line 119
Code: Select all
$uploadDIR = '/home/me/domains/mysite.com/public_html/upload';
$file = $_FILES['image_data']['name'];
str_replace(' ', '_', '/', $file);
$fileTemp = $_FILES['image_data']['tmp_name'];
$random_file = hash(sha1, $_POST['post_id']);
$strip1 = substr($random_file, 4, 2);
$strip2 = substr($random_file, 8, 2);
$filename = "$random_file/$strip1/$strip2";
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
// create an array of permitted MIME types
$permitted = array('image_data/gif', 'image_data/jpeg', 'image_data/pjpeg', 'image_data/png');
if (!$permitted) {
$error[] = 'Sorry, your file type is not recognized.';
} else {
$type == $_FILES['image_data']['type'];
}
// check that file is within the permitted size
if ($_FILES['image_data']['size'] > MAX_FILE_SIZE) {
$error[] = 'Sorry, but your file is too large.';
}
if (!$error) {
if (!file_exists("$uploadDIR/$filename")) {
move_uploaded_file($fileTemp, "$uploadDIR/$file/$filename");
}