PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2012, 06:01 AM
UkraineIsHere UkraineIsHere is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 9 UkraineIsHere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 22 sec
Reputation Power: 0
File uploading notices

Hello guys. I am trying to upload images to my website. but i got notice saying:

Notice: Undefined variable: image_temp in Z:\home\localhost\www\visual2\visual2\upload_image.php on line ( i put a comment where it shows a notice)

Notice: Undefined variable: image_ext in Z:\home\localhost\www\visual2\visual2\upload_image.php on line ( i put a comment where it shows a notice)

Notice: Undefined variable: album_id in Z:\home\localhost\www\visual2\visual2\upload_image.php on line ( i put a comment where it shows a notice)

i can see i have files in my database but with no ''album_id '' and 'ext' tables filled in.

Here is the code:

PHP Code:
<?php
  
if(isset($_FILES['image']) && $_POST['album_id'] ) {
    
 
$image_name $_FILES['image'] ['name'] ;
 
$image_size $_FILES ['image'] ['size']; 
 
$image_temp $_FILES ['image'] ['tmp_name'];

$allowed_ext = array('jpeg','jpg','png','gif');
$image_ext strtolower(end(explode('.'$image_name)));

$album_id $_POST['album_id'];

$errors = array();

if(empty(
$image_name) || empty($album_id)) {
$errors [] = 'Something is missing';

}else {

    if(
in_array($image_ext$allowed_ext) ===false) {
             
$errors [] = 'File type isn\'t allowed';
       } 

       if(
$image_size 2097152) {
          
$errors [] = 'Maximum size is 2 mb';
        }

        if(
$album_check($album_id) ===false) {
            
$errors [] = 'Could not upload to that album';
        }
    }
}

if(!empty(
$errors)) {
    foreach(
$errors as $error) {
        echo 
$error'<br />';
    }
    }else{

    
upload_image($image_temp$image_ext$album_id); //shows that i have undefined veriables  here, why?
    
}


<
form action="" method="POST" enctype ="multypart/form-data">

    <
p>Choose a file : <input type="file" name="image" /></p>
    <
p>
        
Choose an album:</br

        <
select name="album_id">
            <?
php 
            
foreach($albums as $album){
            echo 
'<option value ="'.$album['id'].'">',$album['name'],'</option>';
}
            
?>

        </select>
    </p>
    <p><input type="submit" value="Upload"/></p>

</form>



<?php    
}
?>


here is the function for it:

<?php
function upload_image($image_temp$image_ext$album_id) {

    
$album_id = (int) $album_id;

    
mysql_query("INSERT INTO images VALUES('','".$_SESSION['user_id']."', $album_id , UNIX_TIMESTAMP(), $image_ext)");

    
$image_id mysql_insert_id();
    
$image_file $image_id.'.'.$image_ext;
    
move_uploaded_file ($image_temp'uploads/'.$album_id.'/'.$image_file);

}

?>


if you know what my mistake is, let me know. i just cant understand why the veriable are undefined.
thanks for reading

Last edited by requinix : November 8th, 2012 at 12:10 PM.

Reply With Quote
  #2  
Old November 8th, 2012, 07:15 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
It is difficult to see since you didn't use [ PHP ] tags around your code or properly indent it (see ManiacDan's New User Guide) but it looks like your 'upload_image' statement is outside the 'if (isset' block. That means you can execute that code when the page is first loaded and before the form is submitted.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old November 8th, 2012, 11:44 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Posts: 2,237 paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level)paulh1983 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 11 h 4 m
Reputation Power: 201
depends on where your braces are.. and i dont wanna figure it out

Reply With Quote
  #4  
Old November 8th, 2012, 12:11 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 29 m 55 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
In the interests of getting an answer,
Quote:
Originally Posted by gw1500se
It is difficult to see since you didn't use [ PHP ] tags around your code or properly indent it (see ManiacDan's New User Guide)

Quote:
Originally Posted by paulh1983
depends on where your braces are.. and i dont wanna figure it out

Fixed.

UkraineIsHere: please read the guide that GW linked to, and next time put [php][/php] tags around your PHP code.

Reply With Quote
  #5  
Old November 8th, 2012, 01:15 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
My original surmise is correct. You are executing 'upload_image' even if those variables have not been set yet. You might try this:
PHP Code:
if (isset($image_temp) && isset($image_ext) && isset($album_id)) {
   
upload_image($image_temp$image_ext$album_id);


Alternatively just move all that into the first 'if' block.

Reply With Quote
  #6  
Old November 9th, 2012, 01:22 PM
UkraineIsHere UkraineIsHere is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 9 UkraineIsHere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
My original surmise is correct. You are executing 'upload_image' even if those variables have not been set yet. You might try this:
PHP Code:
if (isset($image_temp) && isset($image_ext) && isset($album_id)) {
   
upload_image($image_temp$image_ext$album_id);


Alternatively just move all that into the first 'if' block.


Thank you very much for trying to help me. i dont get any errors now. I now can't upload files to the database. it worked before. even errors [] = ... don't work. i guess i do something completely wrong with my functions. WHat do you think?

Thanks

Reply With Quote
  #7  
Old November 9th, 2012, 01:39 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
All my code did was prevent calling 'upload_image' if all the variables were not set. If they are not set when they should be then that is a logic problem you need to resolve. I'm not sure what you mean by "can't upload files to the database." Surely you are not trying to put images into your database are you? In any case I will presume you mean your insert is not working. The first step is to output the generated query string an make sure it is what you expect. Then you should try to copy and paste that string into a command line to see if it works and make adjustments from there.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > File uploading notices

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap