Jump to content

Uploading Images, working, but need to change save location


blesseld

Recommended Posts

Hey,

 

I have been playing around with this... and it currently saves to the directory that this .php file is in.

 

public_html->Course->Uploadfile.php

 

So it's saving to Course folder,  I want to create an uploads folder within "Course" and save the images there,  I Tried researching  move_uploaded_file  but there is no clear way on changing the directory for the file destination.  any help would be appreciated.

 

if (isset($_POST['text'])) {
    $text = sanitizeString($_POST['text']);
    $text = preg_replace('/\s\s+/', ' ', $text);
    $query = "SELECT * FROM adccprofiles WHERE user='$user'";
    if (mysql_num_rows(queryMysql($query))) {
        queryMysql("UPDATE adccprofiles SET text='$text'
where user='$user'");
    } else {
        $query = "INSERT INTO adccprofiles VALUES('$user', '$text')";
        queryMysql($query);
    }
} else {
    $query = "SELECT * FROM adccprofiles WHERE user='$user'";
    $result = queryMysql($query);
    if (mysql_num_rows($result)) {
        $row = mysql_fetch_row($result);
        $text = stripslashes($row[1]);
    } else
        $text = "";
}
$text = stripslashes(preg_replace('/\s\s+/', ' ', $text));
if (isset($_FILES['image']['name'])) {
$saveto = "$user.jpg";
    move_uploaded_file($_FILES['image']['tmp_name'], $saveto);
    $typeok = true;
    switch ($_FILES['image']['type']) {
        case "image/gif":
            $src = imagecreatefromgif($saveto);
            break;
        case "image/jpeg": // Both regular and progressive jpegs
        case "image/pjpeg":
            $src = imagecreatefromjpeg($saveto);
            break;
        case "image/png":
            $src = imagecreatefrompng($saveto);
            break;
        default:
            $typeok = false;
            break;
    }
    if ($typeok) {
        list($w, $h) = getimagesize($saveto);
        $max = 100;
        $tw = $w;
        $th = $h;
        if ($w > $h && $max < $w) {
            $th = $max / $w * $h;
            $tw = $max;
        } elseif ($h > $w && $max < $h) {
            $tw = $max / $h * $w;
            $th = $max;
        } elseif ($max < $w) {
            $tw = $th = $max;
        }
        $tmp = imagecreatetruecolor($tw, $th);
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h);
        imageconvolution($tmp, array( // Sharpen image
            array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1)), 8, 0);
        imagejpeg($tmp, $saveto);
        imagedestroy($tmp);
        imagedestroy($src);
    }
}
echo "<br />";
showProfile($user);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.