[solved, thanks feyd] Image upload wont work
Posted: Sat Jun 09, 2007 4:52 pm
hello, im quite stuck.
im new to uploading files and ive just created this script to upload images to a folder called tut_images.
once it has been added, i will put the filename into a sql database ready for calling in future.
i was wondering if anybody could spot the problem, thanks.
heres the script, it says the image has been added but it has not, the folder is chmod'ed to 777.
ive exited early just while testing.
heres the form that does the magic:
thanks for any help
im new to uploading files and ive just created this script to upload images to a folder called tut_images.
once it has been added, i will put the filename into a sql database ready for calling in future.
i was wondering if anybody could spot the problem, thanks.
heres the script, it says the image has been added but it has not, the folder is chmod'ed to 777.
Code: Select all
if(isset($_POST['name'])){//check to see if the user has added one
//handle tutorial image first
if(isset($_FILES['tut_image'])){//check to see if an image has been uploaded
//make sure its a gif or jpeg
if(eregi('^image/p?jpeg(;.*)?$', $_FILES['tut_image']['type'])
or eregi('^image/gif(;.*)?$', $_FILES['tut_image']['type'])){
if(eregi('^image/p?jpeg(;.*)?$', $_FILES['tut_image']['type'])){
$extenstion = '.jpg';
}
else{
$extenstion = '.gif';
}
$file = time() . $_SERVER['REMOTE_ADDR'] . $extenstion;//prepare file name
$filename = $_SERVER['DOCUMENT_ROOT'] . "/tut_images/" . $file;//prepare file name and directory
if(!is_uploaded_file($_FILES['tut_image']['tmp_name']) && copy($_FILES['tut_image']['tmp_name'], $filename)){
exit('p>Unable to add image</p>');
}
else{
echo "<p>Image Added!</p>";
}
}
else{
exit('Only .jpg and .gif file extensions allowed');
}
}
exit();ive exited early just while testing.
heres the form that does the magic:
Code: Select all
<form name="add_tut" method="post" enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']; ?>">
<label>Tutorial Name:<br />
<input type="text" name="name" />
</label><br /><br />
<label>Tutorial Image:<br />
<input type="file" name="tut_image" />
</label><br /><br />
<label>Description:<br />
<input type="text" name="description" />
</label><br /><br />
<label>Keywords:<br />
<input type="text" name="keywords" />
</label><br /><br />
<p>In Category's:</p>
<?php
//get tutorial categorys
$sql = @mysql_query("SELECT * FROM tutorial_categorys;");
if(!$sql){
exit("unable to retreive tutorial categorys");
}
while($cat = mysql_fetch_array($sql)){
$cat_id = $cat['id'];
$cat_name = $cat['name'];
echo "<label><input type=\"checkbox\" name=\"cats[]\" value=\"$cat_id\" />$cat_name</label><br /><br />";
}
$oFCKeditor = new FCKeditor('content');
$oFCKeditor->BasePath = '../fckeditor/';
$oFCKeditor->Value = "";
$oFCKeditor->Width = '490' ;
$oFCKeditor->Height = '500' ;
$oFCKeditor->Create();
?>
<br />
<input type="submit" value="Save Tutorial">
</form>thanks for any help