Jump to content

NEWBIE IN NEED OF HELP


thedualmind

Recommended Posts

I noticed that the problem I am having seems to have been the initiation process of many php users before me so I don't feel as alone in this. My problem: I am attempting to run a php upload script that will enable (select) users to upload files (pictures only for now) to my hosting server. I have been able to confirm that it successfully checks and verifies the size and extension type, however I have not been able to get past this message:"Sorry... something went horribly awry." I highlighted this portion of the php code page displayed below. I am not sure what is missing in the script. My guess is that the directory is not right. !!!SOMEONE PLEASE HELP!!! I have the code for my form page as well as the php script page just below:

 

FORM PAGE

<body>

 

<table width="941" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">

  <!--DWLayoutDefaultTable-->

  <tr>

    <td width="941" height="16"></td>

  </tr>

  <tr>

    <td height="624" valign="top">

      <div align="center"><form method='POST' name='my_form' enctype='multipart/form-data' action='gdform.php'>

          <div align="left">

            <input type='hidden' name='MAX_FILE_SIZE' value="262144" />

            <font color="#FFFFFF"><strong>Which image?</strong></font>

            <input name="upload_file" type="file" />

            <br />

            <br />

            <input type="submit" value="Send Selected Image" />

          </div>

        </form>

      </div>

 

 

      <table width="100%" height="129" border="1">

        <tr>

          <td bordercolor="#FFFFFF">

<div align="center"><font color="#FFFFFF" size="+4" face="Georgia, Times New Roman, Times, serif"><strong><u>MEMBERS ONLY </u></strong></font></div></td>

        </tr>

      </table>

      <p align="center"> </p>

      <div align="left"></div></td>

  </tr>

</table>

 

</body>

 

 

PHP CODE PAGE:

 

<?php

 

$err_upload = "";

 

$image_file = $_FILES['upload_file'];

$temporary_name = $image_file['tmp_name'];

 

if (is_uploaded_file($temporary_name)) {

 

// get image information

$image_metadata = getimagesize($temporary_name);

 

if ($image_metadata) {

$image_width = $image_metadata[0];

$image_height = $image_metadata[1];

$image_type = $image_metadata[2];

 

$save_name = $temporary_name;

 

switch ($image_type)

{

case IMAGETYPE_GIF:

$save_name .= ".gif";

break;

case IMAGETYPE_PNG:

$save_name .= ".png";

break;

default:

$err_upload = "Sorry… we only allow gif and png images.";

break;

}

 

if (! $err_upload) {

if (move_uploaded_file($tmp_name, "php_uploads/gdform/$save_name")) {

// you might update a database with key information here so

// that the image can be used later

} else {

$err_upload = "Sorry… something went horribly awry.";

}

}

}

 

} else {

 

// some error occurred: handle it

switch ($image_file['error'])

{

case 1: // file too big (based on php.ini)

case 2: // file too big (based on MAX_FILE_SIZE)

$err_upload = "Sorry… image too big.";

break;

case 3: // file only partially uploaded

case 4: // no file was uploaded

case 6: // missing a temporary folder

case 7: // failed to write to disk (only in PHP 5.1+)

$err_upload = "Sorry… failed to upload… problem with server.";

break;

}

}

 

if ($err_upload) {

print $err_upload;

} else {

print "Success!!!";

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/60451-newbie-in-need-of-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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