Jump to content

Archived

This topic is now archived and is closed to further replies.

rallokkcaz

file upload script help!!

Recommended Posts

I can't figure out how to get this to upload to the server
and then if its possible a thumbnail of the pic under that

[code]<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br><input type="submit" name="Submit" value="Submit">
<br>&nbsp;
<?php
if(isset($Submit)){
  $file=$_FILES['imagefile']['name'];
  $filetype=substr($file,-4);
  if($filetype=="jpeg"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".jpg"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".png"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".gif"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }else{
    echo"<br><span class="subtitle">Upload Error</span>";
    echo"<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
  }
}
?>
</form>
[/code]
pleeze help!

Share this post


Link to post
Share on other sites
You cannot use $Submit unless globals are turned on, which they are not by default you have to use $_POST['Submit']

Ray

Share this post


Link to post
Share on other sites
where would i put the script to upload it to the database?
and if possible make a thumb nail of it?

Share this post


Link to post
Share on other sites
Warning: copy(images/BEN.png) [function.copy]: failed to open stream: No such file or directory in /home/pokebash/public_html/pic_upload.php on line 24
Could not copy
that was the error message i just got what should i do to fix it.
[code]<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br><input type="submit" name="Submit" value="Submit">
<br>&nbsp;
<?php
if(isset($_POST['Submit'])){
  $file=$_FILES['imagefile']['name'];
  $filetype=substr($file,-4);
  if($filetype=="jpeg"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".jpg"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".png"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }elseif($filetype==".gif"){
    copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])
    or die("Could not copy");
    echo"<br>Upload Complete";
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name']."";
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size']."";
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>";
  }else{
    echo"<br><span class=\"subtitle\">Upload Error</span>";
    echo"<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
  }
}
?>
</form>
[/code]

Share this post


Link to post
Share on other sites
That means it can't find the directory

try using the absolute path instead

replace these lines
[code]copy($_FILES['imagefile']['tmp_name'],"images/".$_FILES['imagefile']['name'])[/code]

with this
[code]copy($_FILES['imagefile']['tmp_name'],"/home/pokebash/public_html/images/".$_FILES['imagefile']['name'])[/code]

Ray

Share this post


Link to post
Share on other sites
thanks but i figuered out what i did wrong i didn't make a folder called images!!
really stupid mistake.

Share this post


Link to post
Share on other sites
now that ive figuered that out instaed of making a a boring directary page where the pics are stored is possible to make a page that the pics can go to ???

Share this post


Link to post
Share on other sites
Yes look up on how to read a directory then lookup the gdlib functions to create thumbnails for the pics.

Can't do everything for ya my man

Ray

Share this post


Link to post
Share on other sites
If you feel like looking at some code ... look at phpWebAlbum (google it) and check it out.  It uses gd to manipulate images.

Share this post


Link to post
Share on other sites
Might also look here. With a little tweaking you can have it do what you want.

(be sure to see the example)

http://www.nstoia.com/toh/technical/listdir/index.php

Lite...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.