path for image upload

megan

Perch
Hi - I am starting to dabble in php and wondering how I determin the path to set for image upload, thanks, megan
 
Here is a pretty basic example...

First make a form to submit the image
Code:
<form method=post enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Image: <input type="file" name="img"><br>
<input type="submit" value="Upload">
</form>

and then add this php to it changing the filepath to like uploaded images or something.. and then you have to make the folder writable by anonymous users. I put in a bunch of variables that store information about the file being uploaded... you can use those to do some error checking before actually saving the file so people dont upload massive things...
PHP:
<?
if($_FILES) {
 //get some attributes which could be used for error checking
 $filesize = $_FILES['img']['size'];
 $filetype = $_FILES['img']['type'];
 $filename = $_FILES['img']['name'];
 $filepath = "yourpathhere/"; //This is where you can enter your own upload path
$filesaveto = "$filepath/$filename";
 $filedim = getimagesize($_FILES['img']['tmp_name']);
 $filewidth = $filedim[0];
 $fileheight = $filedim[1];


// Move the temp upload file to its final location 
if(move_uploaded_file($_FILES['img']['tmp_name'],$filesaveto))) {
echo "Upload Sucessful";
}
else {
echo "Upload Failed";
}

}
?>
 
Hi & thanks! I really appreciate the time you took to post the example and can hardly wait to get into it, but what I was wondering is exactly how do I format the path itself, does it derive from my webroot? or the host drive letter or? how do I figure out just extactly what the path is supposted to be to get to my desired directory??? thanks, Megan
 
ooooh when tyou upload it the way i did in my script.. it is just relative..

so you can do like "images/" no need for full paths
 
Back
Top