Jump to content

image uploads but extension not showing


$php_mysql$

Recommended Posts

what am i doing wrong here friends?

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

 

the image gets uploaded as username01234 the .jpg is not showing?

Link to comment
Share on other sites

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;

$aNew=pathinfo( $_FILES['uploaded']['name']);
$target = $target . "." . $aNew['extension'];

// $target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

 

Maybe this helps ?

Link to comment
Share on other sites

this is a bit of coding i got for resizing image but im not sure how i would go using it with my codes above

 

global $uploadPath;
$imagepath = uploadFile($_FILES['image'], $uploadPath);
// code to resize and save the original image
$image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$thumb_path = 'image_thumbs/thumb_'.$_FILES['image']['name'];
$image->save($thumb_path);
//image resize end

unlink($imagepath); //delete the original file


 

im actually refering to this article

http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php

 

dont know how to use it.

Link to comment
Share on other sites

still confused, never actually used image resize before nor got too much idea

 

i did this

 

$image = new SimpleImage();

$image->load($imagepath);

$image->resize(204,250);

$image->save($_FILES["image"]["name"]);

 

but i get

 

Parse error: parse error in C:\wamp\www\edit\index.php on line 558

Link to comment
Share on other sites

here is my whole coding

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target.basename($_FILES['ad_image']['name']) ;
$ok=1;

if (file_exists("images_thumbs/" . $_FILES["ad_image"]["name"]))
      {
echo "<p align=\"center\">";
      echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>";

echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";    
}else{


    $image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$image->save($_FILES["image"]["name"]);

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['ad_image']['tmp_name'], $target)){
echo "<p align=\"center\">";

echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>";
echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";
}
else{
echo "<p align=\"center\">";

echo "Sorry, there was a problem uploading your file.<br/>";
echo "</p>";
}
}

 

 

Link to comment
Share on other sites

here is my whole coding

 

$target = "images_thumbs/";
$randomnum=rand(0000,9999);
$target = $target.getnick_username($username).$randomnum;
$target = $target.basename($_FILES['ad_image']['name']) ;
$ok=1;

if (file_exists("images_thumbs/" . $_FILES["ad_image"]["name"]))
      {
echo "<p align=\"center\">";
      echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>";

echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";    
}else{


    $image = new SimpleImage();
$image->load($imagepath);
$image->resize(204,250);
$image->save($_FILES["image"]["name"]);

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['ad_image']['tmp_name'], $target)){
echo "<p align=\"center\">";

echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>";
echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>";
echo "</p>";
}
else{
echo "<p align=\"center\">";

echo "Sorry, there was a problem uploading your file.<br/>";
echo "</p>";
}
}

 

Seeing this, I think you don't know what you are doing. Although suggested previously, your extension is still missing.

The resize-class you mention re-saves the resized picture. If you give it a name as you do, you will never know where it will be saved.

If you say 'Parse error: parse error in C:\wamp\www\edit\index.php on line 558' nobody but you can guess what line that is.

You have to provide more information, and take the advices you get a bit more seriously. They are meant to help you. :-\

Link to comment
Share on other sites

Okay, I'll try to guide you through it:

[*]from the site you mentioned, (http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php) you copy ALL of the text from the first file (below 'The code') and save it on your computer with the name SimpleImage.php

 

[*]In the top of your own php-file, the one where you are busy with uploading your picture, you enter: include('SimpleImage.php');

You may have to add a path to that file, depending on the location where you saved it.

 

[*]

At this moment that complete class SimpleImage is now part of your own coding.

 

[*]

At the moment you want to resize an image, that class wants to know 3 things: the name of the picture you want to resize, the size you want, and the name you want to give to the resize picture.

 

[*]

first you start the class with:

$image = new SimpleImage();        // your copy of the class is now called $image

 

[*]

Now you tell that class the name of your picture:

$image->load('picture.jpg');          // replace 'picture.jpg' with the name of your picture. This may also be a variable.

 

[*]

Next you tell the class what size you want:

$image->resize(250,400);            // take a guess ...

 

[*]

Now give the class the name of the resized picture and tell it to do it's job:

$image->save('picture2.jpg');      // I think it is unwise to give it the same name.

 

 

Got it now?

 

Link to comment
Share on other sites

is this correct?

 

$target = "images_thumbs/";
$randomnum=rand(00000000,99999999);
$oldname = $target.$randomnum.getnick_id($id).$randomnum;
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;
$ok=1;

    $target= new SimpleImage();
$newname->load($newname);
$newname->resize(204,250);	
    $newname->save($target);

 

guess not i get this error Fatal error: Call to a member function load() on a non-object in C:\wamp\www\edit\index.php

Link to comment
Share on other sites

is this correct?

 

$target = "images_thumbs/";
$randomnum=rand(00000000,99999999);
$oldname = $target.$randomnum.getnick_id($id).$randomnum;
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;
$ok=1;

    $target= new SimpleImage();
$newname->load($newname);
$newname->resize(204,250);	
    $newname->save($target);

 

guess not i get this error Fatal error: Call to a member function load() on a non-object in C:\wamp\www\edit\index.php

 

Did you include the complete class as I mentioned earlier?

 

Put the next line after    $oldname = $target.$randomnum.getnick_id($id).$randomnum;

echo 'oldname='.$oldname.'<br/>';

 

and put this line after  $newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;

echo 'newname='.$newname.'<br/>';

 

Then you see what you made of it.

 

Link to comment
Share on other sites

Now you can see what's wrong.

 

$oldname=$_FILES['ad_image']['name'];
$newname="images_thumbs/".rand(00000000,99999999).getnick_id($id).$_FILES['ad_image']['name'];

$image= new SimpleImage();
$image->load($oldname);
$image->resize(204,250);	
$image->save($newname);

Link to comment
Share on other sites

did this

$oldname = $target.$_FILES['ad_image']['name'];
$newname = $oldname.$randomnum.basename($_FILES['ad_image']['name']) ;

$ok=1;
$image= new SimpleImage();
$image->load($oldname);
$image->resize(204,250);	
$image->save($newname);

 

and i get error

 

Warning: getimagesize(images_thumbs/Water lilies.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\wamp\www\edit\image_resize.php on line 14

 

Warning: imagesx() expects parameter 1 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 46

 

Warning: imagesy() expects parameter 1 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 49

 

Warning: imagecopyresampled() expects parameter 2 to be resource, null given in C:\wamp\www\edit\image_resize.php on line 68

 

 

Link to comment
Share on other sites

oh yes i removed basename etc this is how i did

 

$oldname = $_FILES['ad_image']['name'];

$newname = $target.$randomnum.getnick_uid($uid).$_FILES['ad_image']['name'] ;

 

$ok=1;

$image= new SimpleImage();

$image->load($oldname);

$image->resize(204,250);

$image->save($newname);

 

 

and the resize_image.php is in the same dir why is it not being found? lol crazy this is

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.