homepage Welcome to WebmasterWorld Guest from 54.243.23.129
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
File Upload
I can't get the script to upload
MrGecko




msg:1308114
 8:57 pm on May 15, 2006 (gmt 0)

i'm trying to make a file upload but it dose not work
may be you can help me

here's the script
<?
$image_folder = "/Image/";
$do = isset($_REQUEST['do'])? trim($_REQUEST['do']) : "";
$image_name = isset($_REQUEST['image_name'])? trim($_REQUEST['image_name']) : "";
switch ($do) {
*case "":
**?>
**<html>
**<form action="index.php">
**<input name="do" type="hidden" value="upload">
**<input name="image_name" type="file" size="15">
**<input type="submit" value="Upload">
**</form>
**</html>
**<?
**break;
*case "upload":
**if(!copy($image_folder, $image_name))
**{
***echo "could not upload";
**}
**break;
}
?>

note * = tab

Mr. Gecko

 

legallyBlind




msg:1308115
 10:53 pm on May 15, 2006 (gmt 0)

try using $_FILES['image_file_name_from_your_form']['tmp_name'] as the source in your copy statement

also you may want to add enctype=\"multipart/form-data\" to your <form> tag
<form action="uploadphoto.php" enctype="multipart/form-data">

dreamcatcher




msg:1308116
 7:05 am on May 16, 2006 (gmt 0)

Hi MrGecko,

Check out this thread and message 29 by Birdman:
[webmasterworld.com...]

It may be of some use to you.

dc

MrGecko




msg:1308117
 7:51 pm on May 18, 2006 (gmt 0)

Not working

jatar_k




msg:1308118
 8:01 pm on May 18, 2006 (gmt 0)

as well as the post that dreamcatcher mentioned you should also read through this

[php.net...]

your code above has quite a few issues, your best bet would be to go with one of the 2 links mentioned and use their examples, they already work. ;)

MrGecko




msg:1308119
 9:33 pm on May 18, 2006 (gmt 0)

i got it to work with this script

<?
$form = "<html>
**<form action=\"index.php\" method=\"post\" enctype=\"multipart/form-data\">
**<input name=\"do\" type=\"hidden\" value=\"upload\">
**<input name=\"image_name\" type=\"file\" size=\"30\">
**<br><label title=\"Overwrite file(s) if exist\" for=\"overwrite\"> Overwrite</label><input style=\"border:0px; background-color:#F7F6F4;\" type=\"checkbox\" name=\"overwrite\" id=\"overwrite\" value=\"1\">
**<br><input type=\"submit\" value=\"Upload\">
**</form>
**</html>";
$image_folder = "./image";
$do = isset($_REQUEST['do'])? trim($_REQUEST['do']) : "";
$image_name = isset($_REQUEST['image_name'])? trim($_REQUEST['image_name']) : "";
switch ($do) {
*case "":
**echo $form;
**break;
*case "upload":
**$allowed = array("gif", "jpg", "png", "bmp", "jpe", "jpeg", "tif");
**
**$current_image = 'image_name';
**
**$image = $_FILES[$current_image]['tmp_name'];
**$image_name = $_FILES[$current_image]['name'];
**$image_name = str_replace(" ", "_", $image_name);
**
**$img_name_arr = explode(".",$image_name);
**$type = end($img_name_arr);
**
**if($image_name == ""){ $img_result .= "<br><font color=\"red\">Image dose not exist try again</font>"; }
**elseif(!isset($overwrite) and file_exists($config_path_image_upload."/".$image_name)){ $img_result .= "<br><font color=\"red\">$image_name -> Image already exist! try again</font>";}
**elseif(!(in_array($type, $allowed) or in_array(strtolower($type), $allowed)) ){
***$img_result .= "<br><font color=\"red\">$image_name ->This type of file is not allowed! try again</font>";
**} else {
***@copy($image, $image_folder."/".$image_name) or $img_result .= "<br><font color=\"red\">$image_name -> Couldn't copy image to server</font><br />Check if file_uploads is allowed in the php.ini file of your server";
***if(file_exists($image_folder."/".$image_name))
***{
****$img_result .= "<br><font color=\"green\">$image_name -> Image was uploaded</font>";
***} else {
****$img_result .= "<br><font color=\"green\">$image_name -> Image was not uploaded! try again</font>";
***}
**}
**echo $img_result;
**echo $form;
**echo "<hr><br>";
**echo $form;
**break;
}
?>

note * = tab

thanks for trying

Mr. Gecko

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved