Oh, Ghod. Haven't these people heard of Google yet?
image upload script
maybe theyre posting here becasue they hold the people that provide help here in high regard, much more reliable than a 10000 result google search!!
anyway, slightly hijacking the thread, is there anyway to allow large uploads and keeping it reliable?? (as in not timing out etc)
thanks
Luke
i have the following html page:
<form action="image3.php" method="POST" enctype="multipart/form-data" onsubmit="return checkform(this);">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="imagefile" size="20" >
<input type="submit" value="Add" name="addIt" class="adminInputBox" onclick="return confirm('You are about to add a new Thread Listing. Is all Information is correct?');">
</form>
and PHP script:
//Check to make sure a file was selected.
//If selected - continue
if (is_uploaded_file($_FILES['imagefile'])) {
//change image name to all lower case
$imgname = strtolower($_FILES['imagefile']['name']);
//remove all spaces from image name
$imgname = str_replace(" ","",$imgname);
//check to see if file already exists
//If not - copy file and continue. Otherwise error out
if (!file_exists("../images/$imgname")) {
copy($_FILES['imagefile']['tmp_name'],"../mages/$imgname");
}
//Send back to page with variables
else {
header("Location: imagerror.php");
}
}
?>
the code seems to submit the image "ok" but when check the folder, the image can not be found... i have set the folder CHMOD to 777 (so there shouldn't be a permissons error)
can anyone see where im going wrong????
thanks
copy($_FILES['imagefile']['tmp_name'],"../mages/$imgname");
Which directory is it going into ?
the directory is "images"
it's not though - it's going to "../mages/"
try changing it to
copy($_FILES['imagefile']['tmp_name'],"/images/$imgname");
Was hoping he'd have a look....
Oh well..
Did changing it help ?
If so - please mark this resolved..
no,
i did see that syntax error...(but i needed to remove the ".." and first slash)...but now works
but i now have the problem, that i said at the start of this thread, that i want to limit the uploads to JPEG images only and of a size no greater than 100k.
can anyone help?
thanks for your time and comments given.....
found some information on this thread about "file types", but can't seem to get it to work ( http://www.phpbuilder.com/board/showthread.php?s=&threadid=10263248&highlight=jpeg )
In your form add the following
<input type="hidden" name="MAX_FILE_SIZE" value="10240">
set the value to whatever you want to limit it to.
this is not secure tho - anyone can change the form to accept a different size. It's worth a shot, but should not be relied on.
The only way really is to check the file size once the image is uploaded and validate it then
Well Yes and you can set the true max size in the PHP.ini, it's usually set to 2meg, we've had sites where we've increased it to allow uploading of video clips as part of the site admin.