I have a news script that allows people to add news to a site. The information is then stored in a PostgreSQL database and spitted out to the respective page.
I want the users to be able to upload images but I have no clue where to look and how to start. Would it upload to a specified folder and then the path stored in the db?
If someone could direct me to a tutorial or give me info on this that'd be great.
Thankswell that is the idea. store the image on the drive and the link to the image in the db.
the manual has a great starting script for you to learn.manual!??! what manual!? www.php.netoh.... that manual! Thanks scoutt!hehe sorry I should have said that in the first palce. Am I missing something here!?
<?
if ($HTTP_POST_VARS{'add_image'}) {
$base_path = "/home/www/nouvelles/images/";
copy( $image, $base_path);
$image_path = "/nouvelles/images/" . $image;
$result = pg_exec ("insert into nouvelles (image) values ('$image_path')");
exit;
} else { ?>
<form method="post" enctype="multipart/form-data">
Upload - <input type="file" name="image">
<input type="submit" name="add_image" value="add image">
</form>
<? } ?>
I get this message
Warning: Unable to create '/nouvelles/images//tmp/phpZzi478': No such file or directoryyes, you have 2 // in the path
also don't use {} for the POST variables, you need [ ] instead
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/nouvelles/images";
copy( $image, $base_path);
$image_path = "/nouvelles/images/" . $image;
$result = pg_exec ("insert into nouvelles (image) values ('$image_path')");
exit;
} else { ?>
<form method="post" enctype="multipart/form-data">
Upload - <input type="file" name="image">
<input type="submit" name="add_image" value="add image">
</form>
<? } ?>In case someone else needed help to upload 1 image and store the path in a database... here's the code!
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/mysite/nouvelles/images/".$image_name;
copy($_FILES['image']['tmp_name'], $base_path);
chmod ($base_path, 0644);
$image_path = "/nouvelles/images/" . $image_name;
$result = pg_exec ("insert into table (image) values ('$image_path') ");
exit;
} else {?>
<form method="post" enctype="multipart/form-data">
Upload image - <input type="file" name="image">
<input type="submit" name="add_image" value="add this image">
</form>
<?}?>
you are using 2 different ways in one ***ntion. you have $image_name which would be correct if register_globals is ON, but then you used $_FILES[] which is used when register_globals is OFF. best guess it wouldn't work if you had register_globals OFF because you won't get the image_name. and the pg_exec is not a php function but maybe a postreg one.
this is what it should be
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/mysite/nouvelles/images/".$_FILES['image']['name'];
copy($_FILES['image']['tmp_name'], $base_path);
chmod ($base_path, 0644);
$image_path = "/nouvelles/images/" . $_FILES['image']['name'];
$result = pg_exec ("insert into table (image) values ('$image_path') ");
exit;
} else {?>
<form method="post" enctype="multipart/form-data">
Upload image - <input type="file" name="image">
<input type="submit" name="add_image" value="add this image">
</form>
<?}?>hmmm.... interesting... I did not know that! Thanks.... works both ways but I changed it to what you said... good point!
I want the users to be able to upload images but I have no clue where to look and how to start. Would it upload to a specified folder and then the path stored in the db?
If someone could direct me to a tutorial or give me info on this that'd be great.
Thankswell that is the idea. store the image on the drive and the link to the image in the db.
the manual has a great starting script for you to learn.manual!??! what manual!? www.php.netoh.... that manual! Thanks scoutt!hehe sorry I should have said that in the first palce. Am I missing something here!?
<?
if ($HTTP_POST_VARS{'add_image'}) {
$base_path = "/home/www/nouvelles/images/";
copy( $image, $base_path);
$image_path = "/nouvelles/images/" . $image;
$result = pg_exec ("insert into nouvelles (image) values ('$image_path')");
exit;
} else { ?>
<form method="post" enctype="multipart/form-data">
Upload - <input type="file" name="image">
<input type="submit" name="add_image" value="add image">
</form>
<? } ?>
I get this message
Warning: Unable to create '/nouvelles/images//tmp/phpZzi478': No such file or directoryyes, you have 2 // in the path
also don't use {} for the POST variables, you need [ ] instead
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/nouvelles/images";
copy( $image, $base_path);
$image_path = "/nouvelles/images/" . $image;
$result = pg_exec ("insert into nouvelles (image) values ('$image_path')");
exit;
} else { ?>
<form method="post" enctype="multipart/form-data">
Upload - <input type="file" name="image">
<input type="submit" name="add_image" value="add image">
</form>
<? } ?>In case someone else needed help to upload 1 image and store the path in a database... here's the code!
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/mysite/nouvelles/images/".$image_name;
copy($_FILES['image']['tmp_name'], $base_path);
chmod ($base_path, 0644);
$image_path = "/nouvelles/images/" . $image_name;
$result = pg_exec ("insert into table (image) values ('$image_path') ");
exit;
} else {?>
<form method="post" enctype="multipart/form-data">
Upload image - <input type="file" name="image">
<input type="submit" name="add_image" value="add this image">
</form>
<?}?>
you are using 2 different ways in one ***ntion. you have $image_name which would be correct if register_globals is ON, but then you used $_FILES[] which is used when register_globals is OFF. best guess it wouldn't work if you had register_globals OFF because you won't get the image_name. and the pg_exec is not a php function but maybe a postreg one.
this is what it should be
<?
if ($HTTP_POST_VARS['add_image']) {
$base_path = "/home/www/mysite/nouvelles/images/".$_FILES['image']['name'];
copy($_FILES['image']['tmp_name'], $base_path);
chmod ($base_path, 0644);
$image_path = "/nouvelles/images/" . $_FILES['image']['name'];
$result = pg_exec ("insert into table (image) values ('$image_path') ");
exit;
} else {?>
<form method="post" enctype="multipart/form-data">
Upload image - <input type="file" name="image">
<input type="submit" name="add_image" value="add this image">
</form>
<?}?>hmmm.... interesting... I did not know that! Thanks.... works both ways but I changed it to what you said... good point!