Jump to content

Recommended Posts

Im trying to upload an image from a form.

Got something like this, but the images dont appear in the uploads folder which is in the route directory.

[quote]<H4>Photo:</H4>
</TD><TD>
<H4><input type="file" name="photo"></H4>
<br>
<?
if(isset( $Submit ))
{
if($_FILES['photo']['error'] ==UPLOAD_ERR_OK)
{
$sImgFileName = $_FILES['photo']['name'].time();
if (move_uploaded_file($_FILES['photo']['tmp_name'], UPLOADS_PATH.'/'.$sImgFileName))
{


}
}
}
?>[/quote]

Any help??
Link to comment
https://forums.phpfreaks.com/topic/25913-uploading-an-image-from-form/
Share on other sites

This is the full index.php

[quote]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
require_once(GLOBALS.'global_fns.php');

if($_REQUEST[mode]=="apply"){
//error checking here

if(!$_REQUEST['name']){$_REQUEST[errors]['Name']='<div class="errors">Please enter your Name</div>';}
if(!$_REQUEST['address1']){$_REQUEST[errors]['Address']='<div class="errors">Please enter your Address</div>';}
if(!$_REQUEST['town']){$_REQUEST[errors]['Town']='<div class="errors">Please enter your Town</div>';}
if(!$_REQUEST['city']){$_REQUEST[errors]['City']='<div class="errors">Please enter your City</div>';}
if(!$_REQUEST['postcode']){$_REQUEST[errors]['Postcode']='<div class="errors">Please enter your Postcode</div>';}
if(!$_REQUEST['country']){$_REQUEST[errors]['Country']='<div class="errors">Please enter your Country</div>';}
if(!$_REQUEST['license']){$_REQUEST[errors]['License']='<div class="errors">Please agree to grant a license for the use of your text/photo</div>';}
if(!$_REQUEST['photo']!="" && !$_REQUEST['memory']!="" && !$_REQUEST['datap']!=""){$_REQUEST[errors]['Optional']='<div class="errors">Please either enter a photo, memory or agree to the Data Protection Act</div>';}
if(validateemail($_REQUEST['email'])===false){$_REQUEST[errors]['Email']='<div class="errors">Please enter a valid Email address</div>';}


if(sizeof($_REQUEST[errors])<1)
{
//if no errors then execute application

$oReaders = new RCLTblReaders();
if (!$oReaders->AddReader($_POST))
{
$_REQUEST['errors']['db'] = 'Please check your details again</div>';
}
$_REQUEST[mode]="complete";

$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address1'];
$town=$_REQUEST['town'];
$city=$_REQUEST['city'];
$postcode=$_REQUEST['postcode'];
$country=$_REQUEST['country'];
$license=$_REQUEST['license'];
$memory=$_REQUEST['memory'];
$photo=$_REQUEST['photo'];
$datap=$_REQUEST['datap'];

$to      = "liverpool@liverpooltest.com";
$subject = "Readers Archive";
$message = 'Name: ' .$name."\n". 'Email: '.$email."\n". 'Address: '.$address."\n". 'Town: '.$town."\n". 'City: '.$city."\n".'Postcode:'.$postcode."\n".'Country: '.$country."\n".'Photo:'.$photo;

$from =  'From: website@liverpooltest.com';
mail($to, $subject, $message, $from);
mail("----@----", $subject, $message, $from);


}
}
?>
<?php
if ($_REQUEST['mode'] == 'complete')
{
echo 'Thank You for submitting your details.';

}
else
{
?>

<? if($_REQUEST[errors]){
?>

<ul>
<?
foreach($_REQUEST[errors] as $error){echo $error;}
?></ul><?
}
?>
<form name="myform" method="post" action="<?=$_SERVER['PHP_SELF']?>">


</center><BLOCKQUOTE><center><P><TABLE BORDER=0 CELLSPACING=0>
<TR>
<TD WIDTH=116>
<H4>Name:</H4>
</TD><TD>
<H4><input name="name" type="text" value="<?=htmlentities(stripslashes($_POST['name']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Address:</H4>
</TD><TD>
<H4><input name="address1" type="text" value="<?=htmlentities(stripslashes($_POST['address1']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Town:</H4>
</TD><TD>
<H4><input name="town" type="text" value="<?=htmlentities(stripslashes($_POST['town']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>City:</H4>
</TD><TD>
<H4><input name="city" type="text" value="<?=htmlentities(stripslashes($_POST['city']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Post Code/Zip Code:</H4>
</TD><TD>
<H4><input name="postcode" type="text" value="<?=htmlentities(stripslashes($_POST['postcode']))?>"/></H4>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Country:</H4>
</TD><TD>
<H4>
<select name="country">
        <option value="United Kingdom">United Kingdom</option>
        <option value="United States of America">United States of America</option>
        <option value="Spain">Spain</option>
        <option value="Italy">Italy</option>
      </select>
<TR>
<TD WIDTH=116>
<H4>Email Address:</H4>
</TD><TD>
<H4><input name="email" type="text" value="<?=htmlentities(stripslashes($_POST['email']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>I agree to grant a license for you to use my text/photograph</H4>
</TD><TD>
<H4><input name="license" type="checkbox" id="license" value="1" <?=($_REQUEST['license'] == '1')?' checked="checked"':''?>/></H4>
<TR>
<TD WIDTH=116>
<H4>Photo:</H4>
</TD><TD>
<H4><input type="file" name="photo"></H4>
<br>
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['photo']['type'] == "image/gif"){
copy ($_FILES['photo']['tmp_name'], "uploads/".$_FILES['photo']['name'])
    or die ("Could not copy");
}
}
?>

<TR>
<TD WIDTH=116>
<H4>Memory:</H4>
</TD><TD>
<H4><textarea NAME="memory" VALUE="<?=htmlentities(stripslashes($_POST['memory']))?>" rows=6 cols=40></textarea></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>Data Protection:</H4>
</TD><TD>
<H4><input name="datap" type="checkbox" id="datap" value="1" <?=($_REQUEST['datap'] == '1')?' checked="checked"':''?>/></H4>


<br class="clear"/>
<input type="Submit" name="submit" value="Submit"  class="button"/>
  <input type="hidden" name="mode" value="apply" />
<?php }//end else?>[/quote]

And a class called Readers.class.php

[quote]<?php

require_once(LOCAL_CLASSES.'/RCLDbBase.class.php');
require_once(GLOBALS.'global_fns.php');


class RCLTblReaders extends RCLDbBase
{
protected $sTableName = "readers";

public function AddReader($aPostData)
{


$sSql = "INSERT INTO readers SET `name`='".$aPostData['name']."', `email`='".$aPostData['email']."',
`address`='".$aPostData['address1']."', `town`='".$aPostData['town']."', `city`='".$aPostData['city']."', `postcode`='".$aPostData['postcode']."',
`country`='".$aPostData['country']."', `license`='".$aPostData['license']."', `memory`='".$aPostData['memory']."', `photo`='".$aPostData['photo']."', `datap`='".$aPostData['datap']."'";

//print $sSql;


return mysql_query($sSql, $this->oDb->GetConnection());
}

}
?>[/quote]
OK, this maybe an issue relating to register_globals.

Where you have these lines near the top of your code:
[code]$memory=$_REQUEST['memory'];
$photo=$_REQUEST['photo'];
$datap=$_REQUEST['datap'];[/code]

Try adding this below:
[code]$submit=$_REQUEST['submit'];[/code]

Regards
Huggie
Been playing around with it, I had it working then I cocked it up again somehow. Dont think I change any of the photo bit tho.

Can anyone see where Im going wrong?

Here is my index.php

[quote]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');
require_once(GLOBALS.'global_fns.php');


$oTblReaders = new RCLTblReaders();

if($_REQUEST[mode]=="apply"){
//error checking here

if(!$_REQUEST['name']){$_REQUEST[errors]['Name']='<div class="errors">Please enter your Name</div>';}
if(!$_REQUEST['address1']){$_REQUEST[errors]['Address']='<div class="errors">Please enter your Address</div>';}
if(!$_REQUEST['town']){$_REQUEST[errors]['Town']='<div class="errors">Please enter your Town</div>';}
if(!$_REQUEST['city']){$_REQUEST[errors]['City']='<div class="errors">Please enter your City</div>';}
if(!$_REQUEST['postcode']){$_REQUEST[errors]['Postcode']='<div class="errors">Please enter your Postcode</div>';}
if(!$_REQUEST['country']){$_REQUEST[errors]['Country']='<div class="errors">Please enter your Country</div>';}
if(!$_REQUEST['license']){$_REQUEST[errors]['License']='<div class="errors">Please agree to grant a license for the use of your text/photo</div>';}
if(!$_REQUEST['photo']!="" && !$_REQUEST['memory']!="" && !$_REQUEST['datap']!=""){$_REQUEST[errors]['Optional']='<div class="errors">Please either enter a photo, memory or agree to the Data Protection Act</div>';}
if(validateemail($_REQUEST['email'])===false){$_REQUEST[errors]['Email']='<div class="errors">Please enter a valid Email address</div>';}

$sEmail = $_REQUEST['email'];
$iDuplicate = $oTblReaders->DuplicateEmail($sEmail);

if(sizeof($_REQUEST['errors'])<1)
//if no errors then execute application
{
//if no errors then execute.


if(isset($_FILES['photo']))
{
if($_FILES['photo']['error'] != UPLOAD_ERR_OK)
{
print("A correct filename is needed a png, jpg or gif! <br />");
}
else{
$sFileName = $_FILES['photo']['name'];
move_uploaded_file($_FILES['photo']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName);
echo "Name: ".$_FILES['photo']['name']."<br />";
        echo "Size: ".$_FILES['photo']['size']."<br />";
        echo "Type: ".$_FILES['photo']['type']."<br />";
        echo "Photo Uploaded Successfully<br />";

}
}
  if($iDuplicate != 0)
{
echo 'please choose a different email this one is already stored in the database';
}
else{
$oTblReaders->AddReader($_POST, $sFileName);
$_REQUEST['mode']="complete";
    }
//send email
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$address=$_REQUEST['address1'];
$town=$_REQUEST['town'];
$city=$_REQUEST['city'];
$postcode=$_REQUEST['postcode'];
$country=$_REQUEST['country'];
$license=$_REQUEST['license'];
$memory=$_REQUEST['memory'];
$photo=$_FILES['photo'];
$datap=$_REQUEST['datap'];

$to      = "liverpool@liverpooltest.com";
$subject = "Readers Archive";
$message = 'Name: ' .$name."\n". 'Email: '.$email."\n". 'Address: '.$address."\n". 'Town: '.$town."\n". 'City: '.$city."\n".'Postcode:'.$postcode."\n".'Country: '.$country."\n".'Photo:'.$photo;

$from =  'From: website@liverpooltest.com';
mail($to, $subject, $message, $from);
mail("---@---", $subject, $message, $from);


}
}
?>

<?php
if ($_REQUEST['mode'] == 'complete')
{
echo '<div class="complete">Thank You for submitting your details.</div>';

}
else
{
?>

<? if($_REQUEST[errors]){
?>

<ul>
<?
foreach($_REQUEST[errors] as $error){echo $error;}
?></ul><?
}
?>

<form name="myform" method="post" action="<?=$_SERVER['PHP_SELF']?>">
</center><BLOCKQUOTE><center><P><TABLE BORDER=0 CELLSPACING=0>
<TR>
<TD WIDTH=116>
<H4>Name:</H4>
</TD><TD>
<H4><input name="name" type="text" value="<?=htmlentities(stripslashes($_POST['name']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Address:</H4>
</TD><TD>
<H4><input name="address1" type="text" value="<?=htmlentities(stripslashes($_POST['address1']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Town:</H4>
</TD><TD>
<H4><input name="town" type="text" value="<?=htmlentities(stripslashes($_POST['town']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>City:</H4>
</TD><TD>
<H4><input name="city" type="text" value="<?=htmlentities(stripslashes($_POST['city']))?>" SIZE=50/>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Post Code/Zip Code:</H4>
</TD><TD>
<H4><input name="postcode" type="text" value="<?=htmlentities(stripslashes($_POST['postcode']))?>"/></H4>
<br class="clear"/>
</TD></TR>
<TR>
<TD WIDTH=116>
<H4>Country:</H4>
</TD><TD>
<H4>
<select name="country">
        <option value="United Kingdom">United Kingdom</option>
        <option value="United States of America">United States of America</option>
        <option value="Spain">Spain</option>
        <option value="Italy">Italy</option>
      </select>
<TR>
<TD WIDTH=116>
<H4>Email Address:</H4>
</TD><TD>
<H4><input name="email" type="text" value="<?=htmlentities(stripslashes($_POST['email']))?>" SIZE=50/>
<br class="clear"/></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>I agree to grant a license for you to use my text/photograph</H4>
</TD><TD>
<H4><input name="license" type="checkbox" id="license" value="1" <?=($_REQUEST['license'] == '1')?' checked="checked"':''?>/></H4>
<TR>
<TD WIDTH=116>
<H4>Photo:</H4>
</TD><TD>
<H4><input type="file" name="photo" ></H4>
<br>

<TR>
<TD WIDTH=116>
<H4>Memory:</H4>
</TD><TD>
<H4><textarea name="memory" rows=6 cols=40 id="memory"><?=($_POST['memory'])?></textarea></textarea></H4>
</TD></TR>
<TR>
<TD WIDTH=210>
<H4>Data Protection:</H4>
</TD><TD>
<H4><input name="datap" type="checkbox" id="datap" value="1" <?=($_REQUEST['datap'] == '1')?' checked="checked"':''?>/></H4>


<br class="clear"/>
<input type="Submit" name="submit" value="Submit"  class="button"/>
  <input type="hidden" name="mode" value="apply" />
<?php }//end else?>[/quote]

And here is my RCTblReaders.class.php

[quote]<?php

require_once(LOCAL_CLASSES.'/RCLDbBase.class.php');
require_once(GLOBALS.'global_fns.php');


class RCLTblReaders extends RCLDbBase
{
protected $sTableName = "readers";

public function AddReader($aPost, $sFileName)
{


$sSql = "INSERT INTO readers SET
`name`='".$aPost['name']."',
`email`='".$aPost['email']."',
`address`='".$aPost['address1']."',
`town`='".$aPost['town']."',
`city`='".$aPost['city']."',
`postcode`='".$aPost['postcode']."',
`country`='".$aPost['country']."',
`license`='".$aPost['license']."',
`memory`='".$aPost['memory']."',
`datap`='".$aPost['datap']."',
`photo`='$sFileName' ";

//print $sSql;


return mysql_query($sSql, $this->oDb->GetConnection());
}
public function DuplicateEmail($sEmail)
{
$sSql = "SELECT COUNT(reader_id) AS num FROM readers WHERE email = '$sEmail' ";

return mysql_result(mysql_query($sSql, $this->oDb->GetConnection()), 0, 'num');
}
}

?>[/quote]

Any help is much appreciated

Thanks
Anyone pleeeease???

Ive been looking over this for about 3 hours and cant find the explanation??

Im getting no value inserted into the photo field and no photos (images) are being uploaded??

Everything else is being inserted into database correctly, its just the photo field.

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