Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-26-2006, 08:50 PM   #1 (permalink)
Squirrel
Junior Member
 
Join Date: Jun 2006
Posts: 1
Send a message via AIM to Squirrel Send a message via MSN to Squirrel
Default Image Uploading Script Question

Hey, I've been writing a simple PHP script that will allow members at my site to upload jpg files. Now I had a lot of problems with this script that I wrote in terms of the directories, (the images were uploading, but not to the right place), so I got the directory problem fixed, but now I keep getting the message that the file was not uploaded successfully.

There are 2 pieces to this script, upload1.php being a form for upload2.php, which contains all of the information.

Here's upload2.php:

PHP Code:
<?php
$file_types_array
=array("jpg");
$max_file_size=1048576;
$upload_dir="../guild";

function 
uploaderFILES($num_of_uploads=1$file_types_array=array("JPG"), $max_file_size=1048576$upload_dir="../guild"){
if(!
is_numeric($max_file_size)){
$max_file_size 1048576;
}
foreach(
$_FILES["file"]["error"] as $key => $value)
{
  if(
$_FILES["file"]["name"][$key]!="")
  {
    if(
$value==UPLOAD_ERR_OK)
    {
      
$origfilename $_FILES["file"]["name"][$key];
      
$filename explode("."$_FILES["file"]["name"][$key]);
      
$filenameext $filename[count($filename)-1];
      unset(
$filename[count($filename)-1]);
      
$filename implode("."$filename);
      
$filename substr($filename015).".".$filenameext;
      
$file_ext_allow FALSE;
      for(
$x=0;$x<count($file_types_array);$x++){
        if(
$filenameext==$file_types_array[$x])

        {
          
$file_ext_allow TRUE;

        }
      } 
// for
      
if($file_ext_allow){
        if(
$_FILES["file"]["size"][$key]<$max_file_size){

          if(
move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
echo(
'<br><br><font color="blue">'.$filename."</font> was successful <br />");
          }
          else { echo(
'<br><br><font color="#FF0000">'.$origfilename."</font> was not successfully uploaded <br />");}
        }
        else  { echo(
'<br><br><font color="#FF0000">'.$origfilename."</font> was too big, not uploaded <br />"); }
      } 
// if
      
else{ echo('<br><br><font color="#FF0000">'.$origfilename." </font>had an invalid file extension<br />");  }
    }
    else{ echo(
'<br><br><font color="#FF0000">'.$origfilename." </font>was not successfully uploaded<br />");  } // else
  
}
}
// funtion

/////////////////////////////////////////

if(isset($_POST["submitted"])){
uploaderFILES($num_of_uploads$file_types_array$max_file_size$upload_dir);

}
// Close the FTP connection
ftp_close($conn_id);
?>


<?php
$imgdir 
'../guild'// the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg opendir($imgdir);

while(
$imgfile readdir($dimg))
{
    if(
in_array(strtolower(substr($imgfile,-3)),$allowed_types))
    {
        
$a_img[] = $imgfile;
        
sort($a_img);
        
reset ($a_img);
    }
}
$totimg count($a_img); // total image number
for($x=0$x $totimg$x++)
{
    
$size getimagesize($imgdir.'/'.$a_img[$x]);
    
// do whatever
    
$halfwidth ceil($size[0]/2);
    
$halfheight ceil($size[1]/2);
    echo 
"<img src= '$imgdir/$a_img[$x]'>";
    echo 
'link: "my site link"'.$a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
}

?>

Can anyone help me? Because I'm not too good at PHP. This is my first script and it's driving me crazy...

EDIT: for "my site", it actually contains the link to where the image uploaded, but these forums won't allow me to post a url...

Last edited by Squirrel : 06-26-2006 at 08:52 PM. Reason: forgot something
Squirrel is offline   Reply With Quote
Sponsored Links
Old 08-04-2006, 05:44 AM   #2 (permalink)
shane.carr
Junior Member
 
shane.carr's Avatar
 
Join Date: Jun 2006
Posts: 28
Default Re: Image Uploading Script Question

Where you have "../guild", put "../guild/"
shane.carr is offline   Reply With Quote
Old 08-04-2006, 02:12 PM   #3 (permalink)
O~Snapple
Moderator Of The Year
 
O~Snapple's Avatar
 
Join Date: Jul 2006
Location: Cali Breeze
Posts: 716
Send a message via MSN to O~Snapple Send a message via Skype™ to O~Snapple
Default Re: Image Uploading Script Question

Some timeis i find it helpfull to add the full directory of where the file will be located
ex. /public_html/etc...
__________________
The Real Truth
Epademik Emcee Esq. New Album The 3rd Finger is in Stores Now!
Snap Marketing Management and Consulting
O~Snapple is offline   Reply With Quote
Old 08-06-2006, 03:55 AM   #4 (permalink)
fares_refaat
Junior Member
 
Join Date: Aug 2006
Posts: 11
Default Re: Image Uploading Script Question

Thankkkkkkkkk You
fares_refaat is offline   Reply With Quote
Old 08-06-2006, 04:43 AM   #5 (permalink)
shane.carr
Junior Member
 
shane.carr's Avatar
 
Join Date: Jun 2006
Posts: 28
Default Re: Image Uploading Script Question

You're welcome!

P.S. Squirrel started this thread; shouldn't he be the one thanking us?
shane.carr is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:26 AM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums