Page 1 of 2
i have a problem with uploading file in IE
Posted: Wed Aug 20, 2008 7:02 pm
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
Re: i have a problem with uploading file in IE
Posted: Wed Aug 20, 2008 9:15 pm
by zootboy
Can you post your html for the upload form?
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 5:48 am
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>
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 7:47 am
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.
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 9:16 am
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
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 10:58 am
by pawarnilesh4u
Please try using path as
$path = "./upload/".next_file_name().".jpg";
or
$path = "give static path here"."/upload/".next_file_name().".jpg";
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 2:36 pm
by lopy_is_me
Re: i have a problem with uploading file in IE
Posted: Thu Aug 21, 2008 6:21 pm
by ghurtado
Please post the full error message that you get when you tried my solution and ignore all others for the time being.
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 5:55 am
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 ???????????
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 7:50 am
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.
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 9:08 am
by zootboy
Is it IE6 or IE7?
I think the underlying problem is that internet explorer is a terrible browser.
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 9:23 am
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.
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 10:11 am
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?
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 10:21 am
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.
Re: i have a problem with uploading file in IE
Posted: Fri Aug 22, 2008 10:50 am
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>