Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Uploading An Image

Asked Modified Viewed 1,313 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

I have a very simple question that I'm not sure of an answer to. Is it possible to use the image upload function in 'INCLUDES/infusions_include.php' to upload an image just by providing a $_POST['image_name'] variable?
0 replies

5 posts

D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

According to the documentation you need at least also specify a destination folder:


https://www.php-fusion.co.uk/infusion...40#page414
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

Actually, no. Those upload_file and upload_image function uses $_FILES, not $_POST.

If you use $_POST, I assume your file/image is already uploaded in the server and need to be moved to a specific folder instead?
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I know about the difference between $_POST and $_FILES. I tried using a call to 'INCLUDES/infusions_include' but could not make it work so I used an older routine from one of my other infusions and it now works great. I had to do a $_POST upload YES or NO and then call my upload routine with $_FILES. Here is my code:
if(isset($_POST['upload']) && ($_POST['upload']) == "yes") {
   include INFUSIONS."event_cal_panel/include/upload_image.php";
} else {
$event_pic = "";
$event_thb = "";
}

... and here is my upload routine:
$max_width = 1024;
$max_height = 768;
$max_tn_size = 110;
$max_pics = 1;
$newpic = $_FILES['event_pic'];
$newname_string="pic_".mt_rand(15000,1500000);
$imginfo = getimagesize($newpic['tmp_name']);
if($imginfo[2]<1 || $imginfo[2]>3) $error='Wrong file type!';
if(!$error) {
if($imginfo[2]==1) {
 $tmpimg=ImageCreateFromGIF($newpic['tmp_name']);
 $filetype = ".gif";
 }
elseif($imginfo[2]==2) {
 $tmpimg=ImageCreateFromJPEG($newpic['tmp_name']);
 $filetype = ".jpg";
 }
elseif($imginfo[2]==3) {
 $tmpimg=ImageCreateFromPNG($newpic['tmp_name']);
 $filetype = ".png";
 }
if($imginfo[0]>$max_width || $imginfo[1]>$max_height) {
 if($imginfo[0]<$imginfo[1]) {
 $new_width = intval($imginfo[0]/($imginfo[1]/$max_height));
 $new_height = $max_height;
 }
 elseif($imginfo[1]<$imginfo[0]) {
 $new_height = intval($imginfo[1]/($imginfo[0]/$max_width));
 $new_width = $max_width;
 }
 else { $new_width=$max_width; $new_height=$max_height; }
} else {$new_width=$imginfo[0]; $new_height=$imginfo[1]; }
$newimg=imagecreatetruecolor($new_width,$new_height);
ImageCopyResized($newimg,$tmpimg,0,0,0,0,$new_width,$new_height,$imginfo[0],$imginfo[1]);
ImageJPEG($newimg,PICPATH.$newname_string.".jpg");
$imginfo = getimagesize(PICPATH.$newname_string.".jpg");
$tmpimg=ImageCreateFromJPEG(PICPATH.$newname_string.".jpg");
if($imginfo[0]<$imginfo[1]) {
$new_width = $imginfo[0]/($imginfo[1]/$max_tn_size);
$new_height = $max_tn_size;
}
elseif($imginfo[1]<$imginfo[0]) {
$new_height = $imginfo[1]/($imginfo[0]/$max_tn_size);
$new_width = $max_tn_size;
}
else { $new_width=$max_tn_size; $new_height=$max_tn_size; }
$newimg=imagecreatetruecolor($new_width,$new_height);
ImageCopyResized($newimg,$tmpimg,0,0,0,0,$new_width,$new_height,$imginfo[0],$imginfo[1]);
ImageJPEG($newimg,THBPATH.$newname_string."_thb.jpg");
   }
if($imginfo[2]==1) {
$event_pic = $newname_string.".gif";
$event_thb = $newname_string."_thb.gif";
}
elseif($imginfo[2]==2) {
$event_pic = $newname_string.".jpg";
$event_thb = $newname_string."_thb.jpg";
}
elseif($imginfo[2]==3) {
$event_pic = $newname_string.".png";
$event_thb = $newname_string."_thb.png";
}
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I've encountered a slight glitch. I want to upload the image without renaming so I tried this:
$newpic = $_FILES['event_pic'];
$mypic = substr($newpic, 0, strrpos($newpic, "."));
$newname_string="$mypic";

It gives me this error.:
strrpos() expects parameter 1 to be string, array given

How do I first convert the $_FILES array value(the uploaded filename) to a string so I can use this function?
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I really think I must be getting senile...!!! The answer is really simple:
$mypic = substr($newpic['name'], 0, strrpos($newpic['name'], "."));
0 replies

Labels

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet