Jump to content

Recommended Posts

Why doesn't this upload the image?

The folder exists, and I am using enctype="multipart/form-data"

 

<?php
include "../../includes/include.php";
if(!isLogged()){
header("Location: ../friends/");
exit;
}
foreach ($_FILES["image"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["image"]["tmp_name"][$key];

	# Create a new file name

	$string = "abcdefghijklmnopqrstuvwxyz0123456789";
	for($i=0;$i<45;$i++){
		$pos = rand(0,36);
		$str .= $string{$pos};
	}
	$ext = getExt($_FILES["image"]["name"][$key]);
        $name = time().$str.$ext;

	# End new file name

	if($ext!='.jpg'||$ext!='.gif'){
		continue;
	}else{
        	move_uploaded_file($tmp_name, "../../images/users/full/$name");
	}
    }
}
header("Location: /friends/");
exit;
?>

Link to comment
https://forums.phpfreaks.com/topic/56661-image-upload/
Share on other sites

hmm alright hope it doesn't fail i use:

<?php
if ($HTTP_POST_FILES['imagefile'.$i]['type'] == "image/jpeg" || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/jpg"
	 || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/pjpeg" || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/pjpg")
?>

Link to comment
https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279860
Share on other sites

works like a charm.

instead of looking for a extension type look for the file type.

<?php
if($filetype = $_FILES['filefield']['type']!='image/pjpeg'){
$save='image/';
$picName=$_FILES['filefield']['name'];
$tmpPath=$_FILES['filefield']['tmp_name'];
$remove=strstr($picName,'.');
$rand = mt_rand(0, 32);
$number = md5($rand . time()).$remove;
$result=copy($tmpPath,"$save$number");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279861
Share on other sites

yeah my password recovery:

<?php

	$rnd[0] = chr(rand(48,57));
	$rnd[1] = chr(rand(48,57));
	$rnd[2] = chr(rand(65,90));
	$rnd[3] = chr(rand(65,90));
	$rnd[4] = chr(rand(65,90));
	$rnd[5] = chr(rand(48,57));
	$rnd[6] = chr(rand(48,57));

	$newpass = $rnd[0].$rnd[1].$rnd[2].$rnd[3].$rnd[4].$rnd[5].$rnd[6];
	$newdbpass = md5($newpass);
?>

kinda off topic but whatever

Link to comment
https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279877
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.