Jump to content

Uploading Images


nikkib20

Recommended Posts

Hi there!

I've inherited a bunch of php backend code to clean up.  I've managed to get through all of it, but the picture upload portion.  Basically each record can have up to 3 possible sizes (thumbnail, large 1, and large 2).  You browse to the image you want to upload and then once the whole form is submitted it is supposed to name it and upload it.

 

As it stands now the form submits and the database is updated with the name of the jpg as it should be...however the server does not get the image.  I'm sure I'm doing something very simple wrong but could use some help.

 

The base form part (works fine):

<tr>

                    <td align="left" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Thumbnail  </font></td>

                    <td width="100%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">

                     

                      No photo

                     

                      <br>

                      <input type="file" name="thumbnail" size="50">

                      <br>

                      <font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif">(Dimensions: 140w x 130h)</font></font></td>

                  </tr>

                  <tr>

                    <td align="left" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Large 1

                      </font></td>

                    <td width="100%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">

                     

                      No photo

                     

                      <br>

                      <input type="file" name="large1" size="50">

                      <br>

                      <font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif">(Dimensions:

                    233w x 187h)</font></font></td>

                  </tr>

                  <tr>

                    <td align="left" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Large 2

                      </font></td>

                    <td width="100%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">

                     

                      No photo

                     

                      <br>

                      <input type="file" name="large2" size="50">

                      <br>

                      <font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif">(Dimensions:

                      233w x 187h)</font></font></td>

                  </tr>

 

The cfm submission portion (which I'm sure has a small bug):

$thumbnail = array("tmp_name" => $_FILES['thumbnail']['tmp_name'],

  "name" => $_FILES['thumbnail']['name'],

  "filesize" => $_FILES['thumbnail']['size'],

  "type" => $_FILES['thumbnail']['type'],

  "file" => $RESORT_IMAGE_DIR."/thumbnails/".mysql_insert_id().".jpg");

 

$large1 = array("tmp_name" => $_FILES['large1']['tmp_name'],

  "name" => $_FILES['large1']['name'],

  "filesize" => $_FILES['large1']['size'],

  "type" => $_FILES['large1']['type'],

  "file" => $RESORT_IMAGE_DIR."/large1/".mysql_insert_id().".jpg");

 

$large2 = array("tmp_name" => $_FILES['large2']['tmp_name'],

  "name" => $_FILES['large2']['name'],

  "filesize" => $_FILES['large2']['size'],

  "type" => $_FILES['large2']['type'],

  "file" => $RESORT_IMAGE_DIR."/large2/".mysql_insert_id().".jpg");

 

// move thumbnail to permanent folder

if (move_uploaded_file($thumbnail['tmp_name'], $thumbnail['file'])) {

chmod($thumbnail['file'], 0644);

                        /*if (file_exists($thumbnail['file'])) {

                                //echo "Picture was added successfully.";

                        }

                        else //echo "Picture wasn't added.. error";*/

}

if (move_uploaded_file($large1['tmp_name'], $large1['file'])) {

chmod($large1['file'], 0644);

                        /*if (file_exists($thumbnail['file'])) {

                                //echo "Picture was added successfully.";

                        }

                        else //echo "Picture wasn't added.. error";*/

}

if (move_uploaded_file($large2['tmp_name'], $large2['file'])) {

chmod($large2['file'], 0644);

                        /*if (file_exists($thumbnail['file'])) {

                                //echo "Picture was added successfully.";

                        }

                        else //echo "Picture wasn't added.. error";*/

}

               

$t_query = mysql_query("UPDATE resorts SET picname='".mysql_insert_id().".jpg"."' WHERE id='".mysql_insert_id()."'");

 

Any help would be really appreciated...I'm sure I'm just doing something simple and dumb wrong but I can't find my error(s).

Thanks so much :)

 

-Nikki

 

 

Link to comment
Share on other sites

heres my uploading images code, make a folder called uploads

<?php 

echo('Upload image<br><br>');


$path = "uploads/"; 

$max_size = 5000000; 



if (!isset($HTTP_POST_FILES['userfile'])) exit; 



if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 



if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>"; exit; } 

if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 



if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists, try calling it a different name.<br>"; exit; } 



$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path . 

$HTTP_POST_FILES['userfile']['name']); 

if (!$res) { echo "upload failed!<br>"; exit; } else { echo "upload sucessful<br><br>"; } 



echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>"; 
echo "File Path: <a href=uploads/".$HTTP_POST_FILES['userfile']['name']." TARGET=_BLANK>uploads/".$HTTP_POST_FILES['userfile']['name']."</a><br>"; 
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>"; 
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>"; 
echo "<img src=uploads/".$HTTP_POST_FILES['userfile']['name']." width=200 height=250><br>";
mysql_connect (your host,your username,your pass); 
mysql_select_db($database) or die('Could not connect to the Database');
$avatar2 = "";   
mysql_query("UPDATE `users` SET `avatar` = 'uploads/".$HTTP_POST_FILES['userfile']['name']."' WHERE `username` = '$user';");
echo "Profile Pic updated";
} else { echo "Wrong file type<br>"; exit; } 

} 



$my_file = $HTTP_POST_FILES['userfile']['name'];


?> 

 

heres the page before that

 

<? echo "<FORM ENCTYPE=multipart/form-data ACTION='?page=Upload Clan Image&clan=$clan' METHOD=POST>"; ?> 

  <p>The file: 
    <INPUT TYPE="file" NAME="userfile" style="border: 1px solid #222222; background-color: #111111; color: #888888">
  </p>
  <p>
    <INPUT TYPE="submit" VALUE="Upload" style="border: 1px solid #222222; background-color: #111111; color: #888888">
  </p>
</FORM> 

Link to comment
Share on other sites

Is there any chance someone can take a look at the code above and let me know where my error is in the CHM code?  I know the form is right, but that I'm doing something really stupid and probably simple wrong on my side with the image code.

 

Thanks I really appreciate it!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.