General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 23rd, 2002, 09:32 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Uploading images to a directory

Hello,

I can upload to a BLOB data type and download....

But what I would like to do is upload the file or picture to a directory....How do you do this?


Thanks,
Attila
__________________
Thanks,
Attila
http://www.glorynaspiration.com
http://www.abitofthings.com

Reply With Quote
  #2  
Old November 24th, 2002, 04:27 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Can somene help with this

Here is what I have worked out so far.

This is not all the code for putting the file name and the location in the database but this is what I am trying to use to upload the file.

PHP Code:
global $strDesc
global 
$fileUpload
global 
$fileUpload_name
global 
$fileUpload_size
global 
$fileUpload_type


//check to see if their is a file with that name already
$base_Dir "Members/";
if (
file_exists($base_Dir.$fileUpload_name))
    {
    echo 
"A file with that name already exist.  Please change your file name and try again.";
    exit;
    }

//upload the file  Line 16 is below this    
copy($fileUpload,$base_Dir.$fileUpload_name); 

if (!
is_uploaded_file ($fileUpload))
    {
        echo 
"<b>$userfile_name</b> couldn't be uploaded !!";
    }

// check whether it has been uploaded

if (is_uploaded_file ($userfile))
    {
        echo 
"<b>$userfile_name</b> uploaded succesfully !!";
    }
//This is line 30 Below for the errors.
if (!move_uploaded_file ($fileUpload$base_Dir))
    { 
        echo 
"Failed to copy $userfile_name";
    } 


I am getting these errors.
Warning: Unable to create 'home/Members/attila gna.jpg': No such file or directory in /home/glorynas/public_html/includes/accountadjustsubmit.php on line 16

Warning: Unable to create 'home/Members/': No such file or directory in /home/glorynas/public_html/includes/accountadjustsubmit.php on line 30

Warning: Unable to move '/tmp/phpaT2Qsj' to 'home/Members/' in /home/glorynas/public_html/includes/accountadjustsubmit.php on line 30

Reply With Quote
  #3  
Old November 25th, 2002, 08:33 AM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
hi there,

This might help u out a bit.

first is a html form that lets you search for a file and upload it.

<html>
<head>
<title>Upload a File</title>
</head>

<body>

<h1>Upload a File</h1>

<form enctype="multipart/form-data" method="post" action="do_upload.php">

<p><strong>File to Upload:</strong><br>
<input type="file" name="your_file" size="30"></p>

<P><input type="submit" name="submit" value="Upload File"></p>

</form>
</body>

</html>

Second is the php script that takes the file and stores it in your chosen directory.

<?

if ($_FILES['your_file'] != "") {

copy($_FILES['your_file']['tmp_name'], "C:\FoxServ\www\".$_FILES['your_file']['name'])
or die("Couldn't copy the file!");

} else {

die("No input file specified");
}

?>

<html>
<head>
<title>Successful File Upload!</title>
<body>

<h1>Success!</h1>

<P>You sent: <? echo $_FILES['your_file']['name'] ?>, a <? echo $_FILES['your_file']['size'];
?> byte file with a mime type of <? echo $_FILES['your_file']['type']; ?>.</p>

</body>
</html>

Remember to replace the directory path with the one that matches your settings / chosen file destination!

Good luck.

Ps. Did you get the blob tutorial working? - if so what web server / php / mysql versions are you running?

Gee

Reply With Quote
  #4  
Old November 25th, 2002, 05:06 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Sorry I should have responded sooner...I got my code working thanks for your response though....WIll look at what you put and what I got to streamline the process.


As far as teh blob. I used the tutorial and was able to upload pictures absolutely no problem. But any other file format was garbage.

I gave up on it....Perfer to have them go to a directory less Database dependent.

If you got a question thought shoot it at me will do my best to help.

I am self tought with PHP and MySql


Reply With Quote
  #5  
Old November 25th, 2002, 07:12 PM
Gee Gee is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 61 Gee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Talking

Hey Attilla,

Any chance of posting your code so I could see it, I am trying to do something similar to what you have been doing and would very much like to see how you tackled the problem!

Or you could mail it to me if you prefer.

Gee

Reply With Quote
  #6  
Old November 26th, 2002, 09:05 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
No problem here you go. This is the page that members fill out.
PHP Code:
<?
$link 
mysql_connect("localhost""logon""pass");
mysql_select_db("database"$link);
$name mysql_query("SELECT name FROM member WHERE name = '$logon' AND password = PASSWORD('$password')"$link);
$num_rows mysql_num_rows($name);
if (
$num_rows <= 0)
    {
        echo 
"<p align= center>You have entered a wrong user name or password.<br></p>";
        echo 
"<div align=center>please try again.";
        exit;
    }
$selectrecord = ("SELECT FROM member WHERE name = '$logon' AND password = PASSWORD('$password')");

$result mysql_query($selectrecord$link) or die ("Query failed");
$num_rows mysql_num_rows($result);

while (
$row mysql_fetch_object($result)){
            
$memberid $row->memberid;
            
$name $row->name;
            
$password $row->password;
            
$gamename $row->gamename;
            
$tfd $row->tfd;
            
$bhd $row->bhd;
            
$gametag $row->gametag;
            
$perweapon $row->perweapon;
            
$picture $row->picturedata;
            
$picturetype $row->$picturetype;
            
$quote $row->quote;
            
$status $row->status;
            
$position $row->position;
            
$email $row->email;
            
$msn $row->msn;
            
$icq $row->icq;
            
$aol $row->aol;
            
$yahoo $row->yahoo;
            
$website $row->website;
?>
<form enctype="multipart/form-data" action="accountadjustsubmit.php" method="post" name="Logon" id="Logon" >
  <table width="50%" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr> 
      <td><input name="memberid"   readonly="" type="hidden" id="logon" value=<? echo "$memberid"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Logon:</font></td>
      <td><input name="name"  readonly="" type="text" id="name" value=<? echo "$name"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Game Name:</font></td>
      <td><input name="gamename"  type="text" id="gamename" value=<? echo "$gamename"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Battle Tag:</font></td>
      <td><input name="gametag"  type="text" id="gametag" value=<? echo "$gametag"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Favorite Weapon:</font></td>
      <td><input name="perweapon"  type="text" id="perweapon" value=<? echo "$perweapon"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Email:</font></td>
      <td><input name="email"  type="text" id="email" value=<? echo "$email"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">TFD? <font size="-2">Y or N</font></font></td>
      <td><input name="tfd"  type="text" id="tfd" value=<? echo "$tfd"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">BHD? <font size="-2">Y or N</font></font></td>
      <td><input name="bhd"  type="text" id="bhd" value=<? echo "$bhd"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Picture: </font></td>
      <td><input type="file" name="fileUpload" size="20"> </td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Quote:</font></td>
      <td><textarea name="quote" id="quote"><? echo "$quote"?></textarea></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Status:</font></td>
      <td><input name="status" readonly="" type="text" id="status" value=<? echo "$status"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Position:</font></td>
      <td><input name="position" readonly="" type="text" id="position" value=<? echo "$position"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">MSN Messinger:&nbsp;</font></td>
      <td><input name="msn" type="text" id="msn" value=<? echo "$msn"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">ICQ #:</font></td>
      <td><input name="icq" type="text" id="icq" value=<? echo "$icq"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">AOL Messinger:</font></td>
      <td><input name="aol" type="text" id="aol" value=<? echo "$aol"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Yahoo Messinger:</font></td>
      <td><input name="yahoo" type="text" id="yahoo" value=<? echo "$yahoo"?>></td>
    </tr>
    <tr> 
      <td bgcolor="#003366"><font color="#FFFFFF">Website address:<br>
        <font size="-1">[url]www.yourwebsite.com[/url]</font> </font></td>
      <td><input name="website" type="text" id="website" value=<? echo "$website"?>></td>
    </tr>
    <tr bgcolor="#000000"> 
      <td align="center"><font color="#FFFFFF"> 
        <input type="submit" name="Submit" value="Submit">
        </font></td>
      <td align="center"><font color="#FFFFFF"> 
        <input type="reset" name="Submit2" value="Reset">
        </font></td>
    </tr>
  </table>
</form>
<? ?>


This is the page that collects the info and puts what you are looking for the picture into the directory...Mind you I do not care what my members upload. This is jsut for an internet gamming squad....So you might want to add some protection code. If you need help with that let me know.

PHP Code:
<?
global $fileUpload//were the file is uploaded to
global $fileUpload_name//file name
global $fileUpload_size//file size
global $fileUpload_type//file type

if ($fileUpload_size 0)
{
    
$test 1;
    
$base_Dir "Directry you want the file to upload...EX /home/yourwebsite/Uploads/";
    
$base_Dir1 "/Uploads/";

    if (!
is_uploaded_file($fileUpload))
        {
            echo 
"The file did not upload";
            exit;
        }

    
$upfile $base_Dir.$fileUpload_name;

    if ( !
copy($fileUpload$upfile))
        {
            echo 
"Could not move the file";
            exit;
        }
    echo 
"<div align=center>Your Picture was uploaded successfully.</div><br><br>";
}
$link mysql_connect("localhost""logon""pass");
mysql_select_db("database"$link);
              
$name mysql_query("SELECT memberid FROM member WHERE memberid = '$memberid'"$link);
$num_rows mysql_num_rows($name);

if (
$num_rows <= 0)
    {
        echo 
"<p align= center>A Database error has occured please try again later.</p>";
        exit;
    }
if (
$test === 1)
    {
        
$updaterecord "UPDATE member SET gamename = '$gamename', gametag = '$gametag', perweapon = '$perweapon', picturedata = '$base_Dir1', picturename = '$fileUpload_name', picturetype = '$fileUpload_type', quote = '$quote', status = '$status', position = '$position', email = '$email', msn = '$msn', icq = '$icq', aol = '$aol', yahoo = '$yahoo', website = '$website' WHERE memberid = '$memberid'";
    }
    else
    {
        
$updaterecord "UPDATE member SET gamename = '$gamename', gametag = '$gametag', perweapon = '$perweapon', quote = '$quote', status = '$status', position = '$position', email = '$email', msn = '$msn', icq = '$icq', aol = '$aol', yahoo = '$yahoo', website = '$website' WHERE memberid = '$memberid'";
    }



$result mysql_query($updaterecord) or die ("Query failed");

echo 
"<div align=center>Your information has been adjusted and saved.</div><br>";
?>



You can see this lage page here. GnA Roster Page
Hope this helps and answers your question....Sorry so Longwinded with the post modiratrs.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Uploading images to a directory


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway