Jump to content

Help Uploading Files Using Php


scotttyz

Recommended Posts

Long time no post :)

 

Having a problem getting this to work and I was wondering if this is a permissions related issue on TCH.

 

Finishing up a inventory listing for a site selling used bikes. No sales from site, just an inventory list. Currently working on the "admin area" to add a new bike to the database. There are 2 pictures being uploaded with each bike. Using a form page to add new records: (NOTE: form works and adds records fine sans file upload)

 

Sniped code

><form action="my_script.php" enctype="multipart/form-data" method="POST" onsubmit="return validate_form(this)" name="addBikeForm">

<tr>
      <td class="formgr">Upload/thumbnails<br>200x150 px </td>
      <td class="formgl"> <input type="file" name="pic_small"></td>
</tr>
<tr>
      <td class="formgr">Upload/Images<br>400x300 px </td>
      <td class="formgl"> <input type="file" name="pic_big"></td>
</tr>

<input type="submit" value="Add Bike"> <input type="reset" value="Reset Form">

 

and the php script:

 

><?php
// lets link up :)
$statusLinkID = mysql_connect("localhost", "XXXXXXXXXXX", "XXXXXXXXX") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("XXXXXXXXXX", $statusLinkID);

//lets write this bad boy
$enter_base_record = mysql_query("INSERT INTO bikes (class, manu_id, sell_price, cc, year, model, miles, notes) VALUES ('$class', '$manu_id', '$sell_price', '$cc', '$year', '$model', '$miles', '$notes')", $statusLinkID);
if ($enter_base_record != TRUE) {die ('I cannot enter the base record because: ' . mysql_error() . '.');}

// Record Number
$lastEntry = mysql_insert_id($statusLinkID);

// do the file move and rename thing
if ($HTTP_POST_FILES['pic_small']['size'] <=0) {die ('Hi, you forgot to put in a small pic or it did not upload corectly. Please delete record number '. $lastEntry . ' completely and renter.');} else {
copy($HTTP_POST_FILES['pic_small']['tmp_name'],"/home/hilmuam/public_html/selling/bikes/".$HTTP_POST_FILES['pic_small']['bike_'. $lastEntry. '_sm']);}

if ($HTTP_POST_FILES['pic_big']['size'] <=0) {die ('Hi, you forgot to put in a big pic or it did not upload corectly. Please delete record number '. $lastEntry . ' completely and renter.');} else {
copy($HTTP_POST_FILES['pic_big']['tmp_name'],"/home/hilmuam/public_html/selling/bikes/".$HTTP_POST_FILES['pic_big']['bike_'. $lastEntry. '_bg']);}

// Remove old files AKA clean your sh!t up
unlink($HTTP_POST_FILES['pic_small']['tmp_name']);
unlink($HTTP_POST_FILES['pic_big']['tmp_name']);

// All done go home and open a beer
header("Location: add.php");
?>

 

The errors I am getting ATM are:

 

Warning: copy(/home/XXXXX/public_html/selling/bikes/): failed to open stream: Is a directory in /home/XXXXXX/public_html/admin/admin_add_bike.php on line 14

 

Warning: copy(/home/XXXXXX/public_html/selling/bikes/): failed to open stream: Is a directory in /home/XXXXXX/public_html/admin/admin_add_bike.php on line 17

 

Any Ideas?? Alternate ways to get this done?

 

I need to rename the images using the Auto_Inc ID given to Dbase record as it is entered so I can script the front end search

Link to comment
Share on other sites

OMFGROFLCOPTER, so simple

 

changes below works great (if I retyped right)

><?php
// lets link up :)
$statusLinkID = mysql_connect("localhost", "XXXXXXXXXXX", "XXXXXXXXX") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("XXXXXXXXXX", $statusLinkID);

//lets write this bad boy
$enter_base_record = mysql_query("INSERT INTO bikes (class, manu_id, sell_price, cc, year, model, miles, notes) VALUES ('$class', '$manu_id', '$sell_price', '$cc', '$year', '$model', '$miles', '$notes')", $statusLinkID);
if ($enter_base_record != TRUE) {die ('I cannot enter the base record because: ' . mysql_error() . '.');}

// Record Number
$lastEntry = mysql_insert_id($statusLinkID);

// do the file move and rename thing
if ($HTTP_POST_FILES['pic_small']['size'] <=0) {die ('Hi, you forgot to put in a small pic or it did not upload corectly. Please delete record number '. $lastEntry . ' completely and renter.');} else {
copy($HTTP_POST_FILES['pic_small']['tmp_name'],"/home/hilmuam/public_html/selling/bikes/bike_'. $lastEntry. '_sm.jpg');}

if ($HTTP_POST_FILES['pic_big']['size'] <=0) {die ('Hi, you forgot to put in a big pic or it did not upload corectly. Please delete record number '. $lastEntry . ' completely and renter.');} else {
copy($HTTP_POST_FILES['pic_big']['tmp_name'],"/home/hilmuam/public_html/selling/bikes/bike_'. $lastEntry. '_bg.jpg');}

// Remove old files AKA clean your sh!t up
unlink($HTTP_POST_FILES['pic_small']['tmp_name']);
unlink($HTTP_POST_FILES['pic_big']['tmp_name']);

// All done go home and open a beer
header("Location: add.php");
?>

 

The errors I am getting ATM are:

 

Warning: copy(/home/XXXXX/public_html/selling/bikes/): failed to open stream: Is a directory in /home/XXXXXX/public_html/admin/admin_add_bike.php on line 14

 

Warning: copy(/home/XXXXXX/public_html/selling/bikes/): failed to open stream: Is a directory in /home/XXXXXX/public_html/admin/admin_add_bike.php on line 17

 

Any Ideas?? Alternate ways to get this done?

 

I need to rename the images using the Auto_Inc ID given to Dbase record as it is entered so I can script the front end search

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...