开发者

how to upload image?

I want upload images in php here is my code

if (isset($_FILES['userfile']['name'])) {
  if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {
    $from = $_FILES['userfile']['tmp_name'];
    $to = "/var/www/html/images/".$_FILES['userfile']['name'];
    $res = move_uploaded_file($from, $to);
    if($res)
    {
      print 'upload success';
    }  
    else
    {
      print 'fail';
    } 开发者_如何转开发              

here i got output fail please tell me correct process

thanks in advance


for images/ have you checked the Permission on Linux it will be 755 or 777.

Note: You don't need absolute path for that you can even do like below.

$to = "images/".$_FILES['userfile']['name'];


The code looks OK, so either the script cannot write to unsifficient rights on the /var/www/html/images/ directory, or that directory does not exist at all. Please check the existance of the directory, and then try to write another file (not through upload) to that directory. Check the directory permissions accordingly.


Please try this, it is already tested and working fine.

<?php
mysql_connect("localhost","root","");
mysql_select_db("kerala");
error_reporting(0);
?>
<?php
if($_POST[sub1]=="Upload")
{
@mkdir("image");
$link="image/".time()."-".$_FILES[fil][name];
copy($_FILES[fil][tmp_name],$link); 
$sql2="insert into `details`(`photo`) values('$link')";
$query2=mysql_query($sql2);
header("location:photo.php");
}
$sql3="select * from `details`";
$query3=mysql_query($sql3);
while ($row=mysql_fetch_array($query3))
{
//echo "<a href=`$row[photo]`><img src='$row[photo]' height='100' width='100'>$row[photo]</a>";
echo "<img src='$row[photo]' height='100' width='100'>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="fil">
<input type="submit" name="sub1" value="Upload">
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜