i have a problem with uploading file in IE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

lopy_is_me
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2008 6:58 pm

i have a problem with uploading file in IE

Post by lopy_is_me »

hi all,
i have created a code for uploading picture files and it works perfectly in firefix but in IE 6 or 7 it gives me this error :

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFuOidl' to '' in /home/site/public_html/upload.php on line 75
error in saving file

my code is after clearing it from spaces :

Code: Select all

 
<?
require("functions.php");
if($_POST["submit"]){
 
$upload_file;
$msg = "";
 
 
if($_FILES["userfile"] == ""){
    $upload_file = false;
    $msg .= "please select a picture file to upload .<br>";
}else{
    $userfile = $_FILES["userfile"];
    $userfile_name = $_FILES["userfile"]["name"];
    $userfile_size = $_FILES["userfile"]["size"];
    $userfile_type = $_FILES["userfile"]["type"];
}
 
if(!($userfile_type == "image/jpg" or $userfile_type == "image/jpeg" or $userfile_type == "image/png" or $userfile_type == "image/gif")){
    $msg .= "<br>extension allowed only : jpg & jpeg & gif & png";
    $upload_file = false;
}else{
    $upload_file = true;
}
 
if($userfile_size > 1024000){
    $msg .= "max file size is : 1024 KB";
    $upload_file = false;
}else{
    $upload_file = true;
}
 
$path = "upload/".next_file_name().".jpg";
// next_file_name() is  function that gets the new name from the BataDase
 
if($upload_file == false){
    echo $msg;
}else{
    if(move_uploaded_file($userfile["tmp_name"], $path)){// line 75 in the original code where the error pointing
        echo "<br>";
        echo "file uploaded successfuly";
        chmod("{$path}",0777);
    }else{
        echo "error in saving file";
    }
}
 
 
 
?>
 
please i need help this code is again run perfectly in Firefox but in IE i don't know what happend
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: i have a problem with uploading file in IE

Post by zootboy »

Can you post your html for the upload form?
lopy_is_me
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2008 6:58 pm

Re: i have a problem with uploading file in IE

Post by lopy_is_me »

the html form is :

Code: Select all

 
 
<form action="upload.php" method="post" enctype="multipart/form-data" >
<table align="center" border="0" cellspacing="10">
    <tr>
    <td>choose a picture : </td>
    <td><input name="userfile"  type="file" size="50" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input name="submit" value="upload" type="submit"/>
    </td>
    </tr>
</table>
</form>
 
 
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: i have a problem with uploading file in IE

Post by ghurtado »

Try changing:

Code: Select all

$path = "upload/".next_file_name().".jpg";
to

Code: Select all

$path = "/home/site/public_html/upload/test.jpg";
and report back what happens.
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: i have a problem with uploading file in IE

Post by zootboy »

OH! I know! In fox, the mime type for images is "image/jpg" or equivalent. In IE, it is "image/pjpeg". Try putting that in and see if it works.

EDIT: Here's a url with all the mime types for IE: http://msdn.microsoft.com/en-us/library/ms775147.aspx
pawarnilesh4u
Forum Newbie
Posts: 6
Joined: Thu Aug 21, 2008 10:16 am
Location: Mumbai - India

Re: i have a problem with uploading file in IE

Post by pawarnilesh4u »

Please try using path as

$path = "./upload/".next_file_name().".jpg";

or

$path = "give static path here"."/upload/".next_file_name().".jpg";
lopy_is_me
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2008 6:58 pm

Re: i have a problem with uploading file in IE

Post by lopy_is_me »

thanks all for trying to help me but i tried all solutions that you gave me but it doesn't work still work fine on firefox but on IE still gives me that <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> error message

what shall i DO ??????????????????????????!!!!!!!!!!!!!!!!!!!!!!!!! :banghead: :banghead: :banghead: :cry: :cry: :cry: :cry:
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: i have a problem with uploading file in IE

Post by ghurtado »

Please post the full error message that you get when you tried my solution and ignore all others for the time being.
lopy_is_me
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2008 6:58 pm

Re: i have a problem with uploading file in IE

Post by lopy_is_me »

i did make the change with what you said ghurtado but it is the same old error message nothing changed

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFPbE4B' to '' in /home/site/public_html/upload.php on line 75

the same line where move_uploaded_file() function

what is making me crazy why is on firefox, safari and Opera works very smoothly and perfectly WHY Microsoft Internet Explorer ???????????
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: i have a problem with uploading file in IE

Post by ghurtado »

Please post the exact source code that produces the error you just posted. Something about what you are doing doesn't match the error you are receiving.
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: i have a problem with uploading file in IE

Post by zootboy »

Is it IE6 or IE7?

I think the underlying problem is that internet explorer is a terrible browser.
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: i have a problem with uploading file in IE

Post by ghurtado »

I think his error has nothing to do with the browser used and the people lending credence to the browser issue are only going to confuse the poster even further.
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: i have a problem with uploading file in IE

Post by zootboy »

Um, the issue is browser-specific, so my question is perfectly valid and important. This may have to do with the way IE passes uploaded data to a php script.

So, IE6 or IE7?
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: i have a problem with uploading file in IE

Post by ghurtado »

You misunderstand how PHP works. PHP runs on the server side. Therefore, when you get an error complaining about not being able to save a file to a specific location (please read the OP), 90% of the time that means there is something wrong with the CODE. The other 10% is an issue with permissions.

You probably didn't notice this in the original error, since you don't seem to have much experience with PHP, but the problem is that the OP is trying to save the file to a BLANK location. This is obvious from the error, if you have ever experienced a similar error in the past.

Have you?

If not, you are not helping the OP solve the issue, but driving him further and further away from a solution. I suggest you only make comments related to areas you have knowledge of or experience with.
lopy_is_me
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2008 6:58 pm

Re: i have a problem with uploading file in IE

Post by lopy_is_me »

first this error is happening in IE7 and IE6

second the full source code i created is :

Code: Select all

 
 
<?php
require("connect.php");
require("head.php");
 
if($_POST["submit"]){
 
    $igroup = $_POST["imggroup"];
 
    $upload_file;
    $msg = "";
 
    if(!($_POST["imgname"] == "" || $_POST["imgdes"] == "")){
        $iname = $_POST["imgname"];
        $ides = $_POST["imgdes"];
        $upload_file = true;
    }else{
        $upload_file = false;
        $msg .= "There is some feilds are empty .";
    }
 
 
    if($_FILES["userfile"] == ""){
        $upload_file = false;
        $msg .= "please choose an image file to upload<br>";
    }else{
        $userfile = $_FILES["userfile"];
        $userfile_name = $_FILES["userfile"]["name"];
        $userfile_size = $_FILES["userfile"]["size"];
        $userfile_type = $_FILES["userfile"]["type"];
    }
 
    if(!($userfile_type == "image/jpg" or $userfile_type == "image/jpeg" or $userfile_type == "image/png" or $userfile_type == "image/gif")){
        $msg .= "<br>image types that allowed are : jpg & jpeg & gif & png";
        $upload_file = false; 
    }else{
        $upload_file = true;
    }
 
    if($userfile_size > 1024000){
        $msg .= "Max file size is 1024 KB .";
        $upload_file = false;
    }else{
        $upload_file = true;
    }
 
    // code for getting rows number of the table
    $q = "SELECT * FROM `images`";
    $res = mysql_query($q);
    $row_num = mysql_num_rows($res);
 
    $path;
    if($userfile_type == "image/jpg"){
        $path = strtolower("upload/".($row_num++).".jpg");
    }
 
    if($userfile_type == "image/jpeg"){
        $path = strtolower("upload/".($row_num++).".jpeg");
    }
 
    if($userfile_type == "image/gif"){
        $path = strtolower("upload/".($row_num++).".gif");
    }
 
    if($userfile_type == "image/png"){
        $path = strtolower("upload/".($row_num++).".png");
    }
 
 
    if($upload_file == false){
        echo $msg;
    }else{
        if(move_uploaded_file($userfile["tmp_name"], $path)){
            echo "<br>";
            echo "file uploaded successfuly";
            chmod("{$path}",0777);
        }else{
            echo "error in saving file";
        }
    }
 
    $n_width = 70;
    $n_height = 100;
 
    // thum dir based on upload dir
    $thum = str_replace("upload/","thum/",$path);
 
    if($userfile_type == "image/gif"){
        $im = ImageCreateFromGIF($path);
        $width = ImageSx($im);
        $height = ImageSy($im);
        $r = $height / $width;
        $h = 120;
        $w = 120 * $r;
        $new_image = imagecreatetruecolor($h, $w);
        imageCopyResized($new_image,$im,0,0,0,0,$h,$w,$width,$height);
        
        if(function_exists("imagegif")){
            ImageGIF($new_image,$thum);
        }elseif(function_exists("imagejpeg")){
            ImageJPEG($newimage,$thum);
        }
        chmod("{$thum}",0777);
    }
 
    if($userfile_type=="image/jpeg" or $userfile_type=="image/jpg"){
        $im=ImageCreateFromJPEG($path);
        $width=ImageSx($im);
        $height=ImageSy($im);
        $r = $height / $width;
        $h = 120;
        $w = 120 * $r;
        $newimage=imagecreatetruecolor($h,$w);
        imageCopyResized($newimage,$im,0,0,0,0,$h,$w,$width,$height);
        ImageJpeg($newimage,$thum);
        chmod("{$thum}",0777);
    }
 
    if($userfile_type=="image/png"){
        $im=ImageCreateFromPNG($path);
        $width=ImageSx($im);
        $height=ImageSy($im);
        $r = $height / $width;
        $h = 120;
        $w = 120 * $r;
        $newimage=imagecreatetruecolor($h,$w);
        imageCopyResized($newimage,$im,0,0,0,0,$h,$w,$width,$height);
        ImagePng($newimage,$thum);
        chmod("{$thum}",0777);
    }
 
    if($upload_file == true){
        // add full size image and thum paths to the database
        $q = "INSERT INTO `images` ( `id` , `img` , `thum` , `name` , `descripe` , `group` )
            VALUES (NULL , '{$path}', '{$thum}' , '{$iname}' , '{$ides}' , '{$igroup}' )";
        $res = mysql_query($q);
        if($res){
            echo "<!--query done ok-->";
        }else{
            echo "<!--query NOT done-->";
        }
    }
 
}
 
?>
<form action="upload.php" method="post" enctype="multipart/form-data" >
<table align="center" border="0" cellspacing="10">
    <tr>
    <td>choose an image file : </td>
    <td><input name="userfile"  type="file" size="50" /></td>
    </tr>
    <tr>
    <td>name : </td>
    <td><input type="textfield" name="imgname" size="50" /></td>
    </tr>
    <tr>
    <td>description : </td>
    <td><input type="textfield" name="imgdes" size="50" /></td>
    </tr>
    <tr>
    <td>choose a group : </td>
    <td>
        <select name="imggroup">
<?php
// get list of groups from the DB
$q = "SELECT * FROM `grp`";
$res = mysql_query($q);
if($res){
    while($row = mysql_fetch_array($res)){
        echo "<option value=\"". $row["id"]."\">".$row["gn"]."</option>";
    }
}
 
?>
        </select>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input name="submit" value="upload" type="submit"/>
    </td>
    </tr>
</table>
</form>
 
<br>
---------------------------------------------------
<br>
</div>
</body>
 
</html>
 
 
Post Reply